rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 89cbc6bdeaafc0f3443b9c1ccfbc22900af03fe2
parent 7155d8bfc8a6a3024b60082600880bf7e72b00fc
Author: vaplv <vaplv@free.fr>
Date:   Mon, 23 Nov 2015 09:43:54 +0100

Fix the str to uint conversion

An error occured when negative numbers were parsed on platform where
UINT_MAX < ULONG_MAX.

Diffstat:
Msrc/cstr.h | 23+++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/cstr.h b/src/cstr.h @@ -110,17 +110,24 @@ cstr_to_ulong(const char* str, unsigned long* dst) static INLINE res_T cstr_to_uint(const char* str, unsigned* dst) { - unsigned long l; res_T res; ASSERT(dst); - res = cstr_to_ulong(str, &l); - if (res != RES_OK) - return res; -#if UINT_MAX < ULONG_MAX - if(l > UINT_MAX) - return RES_BAD_ARG; +#if UINT_MAX == ULONG_MAX + { + unsigned long l; + res = cstr_to_ulong(str, &l); + if(res != RES_OK) return res; + *dst = (unsigned)l; + } +#else /* UINT_MAX < ULONG_MAX */ + { + long l; + res = cstr_to_long(str, &l); + if(res != RES_OK) return res; + if(l > UINT_MAX) return RES_BAD_ARG; + *dst = (unsigned)l; + } #endif - *dst = (unsigned) l; return RES_OK; }