commit dcd8530bcced262cd1689d2072ed416193072659
parent ce10469d661e72d3d322eda9a42983d7df0d96ca
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 2 Nov 2015 16:57:45 +0100
Bugfix on cstr_to_float
Prevented test_cstr to success
Was bad on-range test after convertion to double
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/cstr.h b/src/cstr.h
@@ -18,6 +18,8 @@
#include "rsys.h"
+#include "math.h"
+
#include <float.h>
#include <limits.h>
#include <stdlib.h>
@@ -46,8 +48,8 @@ cstr_to_float(const char* str, float* dst)
ASSERT(dst);
res = cstr_to_double(str, &dbl);
if(res != RES_OK) return res;
- if((dbl > 0.0 && dbl < FLT_MIN && dbl > FLT_MAX)
- || (dbl < 0.0 && dbl >-FLT_MIN && dbl <-FLT_MAX))
+ double tmp = fabs(dbl);
+ if (tmp != INF && (tmp < FLT_MIN || tmp > FLT_MAX))
return RES_BAD_ARG;
*dst = (float)dbl;
return RES_OK;