From: raster Date: Thu, 14 Jun 2012 08:46:58 +0000 (+0000) Subject: fix divide by 0 possible errors in embryo fp support X-Git-Tag: 2.0_alpha~4^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=e68e1a2a6281c4c3f94129c98febaa2f9fc01e1c;p=framework%2Fuifw%2Fembryo.git fix divide by 0 possible errors in embryo fp support git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/embryo@72112 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/ChangeLog b/ChangeLog index 51b3d50..97da875 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,3 +35,9 @@ 2012-04-26 Carsten Haitzler (The Rasterman) 1.2.0 release + +2012-06-14 Carsten Haitzler (The Rasterman) + + * Fix divide by 0 possibilities in the fp support so no FPE is + produced (bad). + diff --git a/src/lib/embryo_float.c b/src/lib/embryo_float.c index 6efa2ae..ffaa87d 100644 --- a/src/lib/embryo_float.c +++ b/src/lib/embryo_float.c @@ -48,6 +48,9 @@ #include "embryo_private.h" #define PI 3.1415926535897932384626433832795f +#ifndef MAXFLOAT +#define MAXFLOAT 3.40282347e+38f +#endif /* internally useful calls */ @@ -114,10 +117,21 @@ _embryo_fp_div(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) { /* params[1] = float dividend (top) */ /* params[2] = float divisor (bottom) */ - float f; + float f, ff; if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; - f = EMBRYO_CELL_TO_FLOAT(params[1]) / EMBRYO_CELL_TO_FLOAT(params[2]); + f = EMBRYO_CELL_TO_FLOAT(params[1]); + ff = EMBRYO_CELL_TO_FLOAT(params[2]); + if (ff == 0.0) + { + if (f == 0.0) + return EMBRYO_FLOAT_TO_CELL(0.0f); + else if (f < 0.0) + return EMBRYO_FLOAT_TO_CELL(-MAXFLOAT); + else + return EMBRYO_FLOAT_TO_CELL(MAXFLOAT); + } + f = f / ff; return EMBRYO_FLOAT_TO_CELL(f); } @@ -238,7 +252,7 @@ _embryo_fp_log(Embryo_Program *ep, Embryo_Cell *params) { /* params[1] = float operand 1 (value) */ /* params[2] = float operand 2 (base) */ - float f, ff; + float f, ff, tf; if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; f = EMBRYO_CELL_TO_FLOAT(params[1]); @@ -250,7 +264,12 @@ _embryo_fp_log(Embryo_Program *ep, Embryo_Cell *params) } if (ff == 10.0) f = log10f(f); else if (ff == 2.0) f = log2f(f); - else f = (logf(f) / logf(ff)); + else + { + tf = logf(ff); + if (tf == 0.0) f = 0.0; + else f = (logf(f) / tf); + } return EMBRYO_FLOAT_TO_CELL(f); }