commit 4cd84904c4bd96b21b133991b796d7f99a7b1912
parent 7f2a18591c6e7713992b4d393eb503a6ac34f4d3
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 3 Nov 2015 17:30:04 +0100
Fix Linux build
Diffstat:
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/cstr.h b/src/cstr.h
@@ -20,6 +20,7 @@
#include "math.h"
+#include <errno.h>
#include <float.h>
#include <limits.h>
#include <stdlib.h>
@@ -44,11 +45,12 @@ static INLINE res_T
cstr_to_float(const char* str, float* dst)
{
double dbl;
+ double tmp;
res_T res;
ASSERT(dst);
res = cstr_to_double(str, &dbl);
if(res != RES_OK) return res;
- double tmp = fabs(dbl);
+ tmp = fabs(dbl);
if (tmp != INF && (tmp < FLT_MIN || tmp > FLT_MAX))
return RES_BAD_ARG;
*dst = (float)dbl;
@@ -108,14 +110,16 @@ cstr_to_ulong(const char* str, unsigned long* dst)
static INLINE res_T
cstr_to_uint(const char* str, unsigned* dst)
{
- unsigned long l;
+ long l;
res_T res;
ASSERT(dst);
- res = cstr_to_ulong(str, &l);
+ res = cstr_to_long(str, &l);
if (res != RES_OK)
return res;
- if (l > (unsigned long) UINT_MAX)
+#if UINT_MAX < ULONG_MAX
+ if(l > UINT_MAX)
return RES_BAD_ARG;
+#endif
*dst = (unsigned) l;
return RES_OK;
}
diff --git a/src/test_cstr.c b/src/test_cstr.c
@@ -121,10 +121,10 @@ main(int argc, char** argv)
CHECK(ul, 2);
CHECK(cstr_to_ulong(" \t+123 \t ", &ul), RES_OK);
CHECK(ul, 123);
- sprintf(buf, "%u", ULONG_MAX);
+ sprintf(buf, "%lu", ULONG_MAX);
CHECK(cstr_to_ulong(buf, &ul), RES_OK);
CHECK(ul, ULONG_MAX);
- sprintf(buf, "%llu", (unsigned long long)ULONG_MAX + 1);
+ sprintf(buf, "%lu%c", ULONG_MAX, '0');
CHECK(cstr_to_ulong(buf, &ul), RES_BAD_ARG);
CHECK(cstr_to_list_double(NULL, dlist, NULL, 3), RES_BAD_ARG);