From: borutr Date: Fri, 19 Oct 2007 19:38:41 +0000 (+0000) Subject: * src/pic16/glue.c: fixed bug #983491 - "Merge duplicate strings X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=f542e052f62b7dcf19a6ea79496237fc9a339032;hp=ad8e676da2decf4ee03908edeffd157e55d6b312;p=fw%2Fsdcc * src/pic16/glue.c: fixed bug #983491 - "Merge duplicate strings function is ineffective" for pic16 tareget * support/scripts/listerr.c: corrected include path * device/lib/_itoa.c: fixed bug #1806402 - _itoa and _uitoa leak to adjacent memory git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4938 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index e64f2bee..0a32df85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ * src/pic16/glue.c: fixed bug #983491 - "Merge duplicate strings function is ineffective" for pic16 tareget * support/scripts/listerr.c: corrected include path + * device/lib/_itoa.c: fixed bug #1806402 - _itoa and _uitoa leak to + adjacent memory 2007-10-18 Maarten Brock diff --git a/device/lib/_itoa.c b/device/lib/_itoa.c index f89ba9e4..40b28a1a 100644 --- a/device/lib/_itoa.c +++ b/device/lib/_itoa.c @@ -13,27 +13,30 @@ radix -> Base of value (e.g.: 2 for binary, 10 for decimal, 16 for hex) ---------------------------------------------------------------------------*/ -#define NUMBER_OF_DIGITS 16 - void _uitoa(unsigned int value, char* string, unsigned char radix) { -unsigned char index, i; -/* char buffer[NUMBER_OF_DIGITS]; */ /* space for NUMBER_OF_DIGITS + '\0' */ - - index = NUMBER_OF_DIGITS; - i = 0; + signed char index = 0, i = 0; + /* generate the number in reverse order */ do { - string[--index] = '0' + (value % radix); - if ( string[index] > '9') string[index] += 'A' - '9' - 1; + string[index] = '0' + (value % radix); + if (string[index] > '9') + string[index] += 'A' - '9' - 1; value /= radix; + ++index; } while (value != 0); - do { - string[i++] = string[index++]; - } while ( index < NUMBER_OF_DIGITS ); + /* null terminate the string */ + string[index--] = '\0'; - string[i] = 0; /* string terminator */ + /* reverse the order of digits */ + while (index > i) { + char tmp = string[i]; + string[i] = string[index]; + string[index] = tmp; + ++i; + --index; + } } void _itoa(int value, char* string, unsigned char radix)