Author: greatlrd Date: Mon May 22 00:26:51 2006 New Revision: 21973
URL: http://svn.reactos.ru/svn/reactos?rev=21973&view=rev Log: Fixing a i64ltoa bug, replacing both version with wine, copy the code from wine cvs 2005-05-21, bug report by wine test
Modified: trunk/reactos/lib/crt/stdlib/witoa.c trunk/reactos/lib/string/itoa.c
Modified: trunk/reactos/lib/crt/stdlib/witoa.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/crt/stdlib/witoa.c?rev=2... ============================================================================== --- trunk/reactos/lib/crt/stdlib/witoa.c (original) +++ trunk/reactos/lib/crt/stdlib/witoa.c Mon May 22 00:26:51 2006 @@ -13,48 +13,45 @@
/* * @implemented + * copy _i64toa from wine cvs 2006 month 05 day 21 */ char* _i64toa(__int64 value, char* string, int radix) { - char tmp[65]; - char *tp = tmp; - int i; - unsigned v; - int sign; - char *sp; + ULONGLONG val; + int negative; + char buffer[65]; + char *pos; + int digit;
- if (radix > 36 || radix <= 1) - { - __set_errno(EDOM); - return 0; - } + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */
- sign = (radix == 10 && value < 0); - if (sign) - v = -value; - else - v = (unsigned)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } + pos = &buffer[64]; + *pos = '\0';
- if (string == 0) - string = (char *)malloc((tp-tmp)+sign+1); - sp = string; + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L);
- if (sign) - *sp++ = '-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; + if (negative) { + *--pos = '-'; + } /* if */ + + memcpy(string, pos, &buffer[64] - pos + 1); + return string; } +
/* * @implemented
Modified: trunk/reactos/lib/string/itoa.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/string/itoa.c?rev=21973&... ============================================================================== --- trunk/reactos/lib/string/itoa.c (original) +++ trunk/reactos/lib/string/itoa.c Mon May 22 00:26:51 2006 @@ -1,46 +1,47 @@ #include <string.h> #include <stdlib.h> +#include <windows.h>
/* * @implemented + * copy _i64toa from wine cvs 2006 month 05 day 21 */ char * _i64toa(__int64 value, char *string, int radix) { - char tmp[65]; - char *tp = tmp; - __int64 i; - unsigned __int64 v; - __int64 sign; - char *sp; + ULONGLONG val; + int negative; + char buffer[65]; + char *pos; + int digit;
- if (radix > 36 || radix <= 1) - { - return 0; - } + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */
- sign = (radix == 10 && value < 0); - if (sign) - v = -value; - else - v = (unsigned __int64)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } + pos = &buffer[64]; + *pos = '\0';
- sp = string; - if (sign) - *sp++ = '-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L); + + if (negative) { + *--pos = '-'; + } /* if */ + + memcpy(string, pos, &buffer[64] - pos + 1); + return string; }