GNOME Bugzilla – Bug 748389
validate-utils: Passing value -1.0 to sqrt() leads to undefined result
Last modified: 2015-06-24 14:44:14 UTC
using sqrt of -1 is not valid and leads to undefined results. when comparing the return value of the fucntion in validate-scenario, it is being checked with ret == -1, so it makes sense to just return -1 in error case.
Created attachment 302269 [details] [review] sqrt(-1) is not valid, hence just returning -1
Can someone review this :)
ping :)
Makes me wonder why sqrt () was used at all. Let me read more of the context code and the history of it.
What I expected. #include <math.h> #include <stdio.h> int main () { printf ("%f\n", sqrt (-1.0)); return 0; } Returns "-nan" Good find! :) One thing though. else { return -1.0; } return -1.0; Why the need for an else there? Change this to be the following and I will merge: if (!setjmp (parser->err_jmp_buf)) { result = _read_expr (parser); if (parser->pos < parser->len - 1) { _error (parser, "Failed to reach end of input expression, likely malformed input"); } else return result; } return -1.0;
Review of attachment 302269 [details] [review]: Nevermind, I know you have limited time. So added my suggestion and pushed your patch. commit 1e3084aa95463547cada647ec4a7d0725b4c43b0 Thanks! Good one.
Thanks Luis :)