From 2239b50494b04b1e89c4478cdbb9ae1625c28b72 Mon Sep 17 00:00:00 2001 From: roybaer Date: Sun, 22 Dec 2024 19:30:26 +0000 Subject: [PATCH] Hackfix and re-enable strtoull and wcstoull, see bug #3798. git-svn-id: https://svn.code.sf.net/p/sdcc/code/trunk@15190 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- sdcc/ChangeLog | 7 +++++++ sdcc/device/lib/strtoull.c | 14 ++++++++++---- sdcc/device/lib/wcstoul.c | 2 +- sdcc/device/lib/wcstoull.c | 16 +++++++++++----- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/sdcc/ChangeLog b/sdcc/ChangeLog index 7891793fa..c9d1dac74 100644 --- a/sdcc/ChangeLog +++ b/sdcc/ChangeLog @@ -1,3 +1,10 @@ +2024-12-22 Benedikt Freisen + + * device/lib/strtoull.c, + device/lib/wcstoul.c, + device/lib/wcstoull.c: + Hackfix and re-enable strtoull and wcstoull, see bug #3798. + 2024-12-21 Philipp Klaus Krause * src/SDCCast.c, diff --git a/sdcc/device/lib/strtoull.c b/sdcc/device/lib/strtoull.c index 63bbf0e32..85f194f20 100644 --- a/sdcc/device/lib/strtoull.c +++ b/sdcc/device/lib/strtoull.c @@ -32,13 +32,13 @@ #include #include #include -#ifdef __SDCC_LONGLONG +#if 0 #include #endif #include #include -#if 0 // Bug 3798 +#ifdef __SDCC_LONGLONG static signed char _isdigit(const char c, unsigned char base) { unsigned char v; @@ -122,10 +122,17 @@ unsigned long long int strtoull(const char *nptr, char **endptr, int base) if (digit < 0) break; +#if 0 range_error |= ckd_mul (&ret, ret, b); range_error |= ckd_add (&ret, ret, digit); - +#else + unsigned long long int oldret = ret; + ret *= b; + if (ret < oldret) + range_error = true; ret += (unsigned char)digit; +#warning INEXACT RANGE ERROR CHECK WILL NOT REPORT ALL OVERFLOWS (fix by implementing ckd_mul and ckd_add for unsigned long long) +#endif } if (endptr) @@ -140,4 +147,3 @@ unsigned long long int strtoull(const char *nptr, char **endptr, int base) return (neg ? -ret : ret); } #endif - diff --git a/sdcc/device/lib/wcstoul.c b/sdcc/device/lib/wcstoul.c index f51255e5a..ed273e02d 100644 --- a/sdcc/device/lib/wcstoul.c +++ b/sdcc/device/lib/wcstoul.c @@ -131,7 +131,7 @@ unsigned long int wcstoul(const wchar_t *nptr, wchar_t **endptr, int base) if (ret < oldret) range_error = true; ret += (unsigned char)digit; -#warning INEXACT RANGE ERROR CHECK WILL NOT REPORT ALL OVERFLOWS (fix by implementing ckd_mul support) +#warning INEXACT RANGE ERROR CHECK WILL NOT REPORT ALL OVERFLOWS (fix by implementing ckd_mul and ckd_add) #endif } diff --git a/sdcc/device/lib/wcstoull.c b/sdcc/device/lib/wcstoull.c index c8ffbdf79..ef1b295b3 100644 --- a/sdcc/device/lib/wcstoull.c +++ b/sdcc/device/lib/wcstoull.c @@ -32,14 +32,14 @@ #include #include #include -#ifdef __SDCC_LONGLONG +#if 0 #include #endif #include #include #include -#if 0 // Bug 3798 +#ifdef __SDCC_LONGLONG static signed char _isdigit(const wchar_t c, unsigned char base) { unsigned char v; @@ -123,10 +123,17 @@ unsigned long long int wcstoull(const wchar_t *nptr, wchar_t **endptr, int base) if (digit < 0) break; - range_error |= ckd_mul(&ret, ret, b); +#if 0 + range_error |= ckd_mul (&ret, ret, b); range_error |= ckd_add (&ret, ret, digit); - +#else + unsigned long long int oldret = ret; + ret *= b; + if (ret < oldret) + range_error = true; ret += (unsigned char)digit; +#warning INEXACT RANGE ERROR CHECK WILL NOT REPORT ALL OVERFLOWS (fix by implementing ckd_mul and ckd_add for unsigned long long) +#endif } if (endptr) @@ -141,4 +148,3 @@ unsigned long long int wcstoull(const wchar_t *nptr, wchar_t **endptr, int base) return (neg ? -ret : ret); } #endif - -- 2.11.4.GIT