Author: greatlrd
Date: Sun May 21 22:54:21 2006
New Revision: 21967
URL:
http://svn.reactos.ru/svn/reactos?rev=21967&view=rev
Log:
Fixing a ultoa bug, replacing both version with wine, copy the code from wine 0.9.0; I did
add a NULL check for the string so it can not bsod. wine ntdll string only report one
error, left to fix, I run wine test on windows 2000 and reactos to compare the result.
Fireball report wine_ntdll_test string crach on windows xp, but it does not crash in
windows 2000.
Modified:
trunk/reactos/lib/crt/stdlib/itoa.c
trunk/reactos/lib/string/itoa.c
Modified: trunk/reactos/lib/crt/stdlib/itoa.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/crt/stdlib/itoa.c?rev=2…
==============================================================================
--- trunk/reactos/lib/crt/stdlib/itoa.c (original)
+++ trunk/reactos/lib/crt/stdlib/itoa.c Sun May 21 22:54:21 2006
@@ -104,37 +104,32 @@
/*
* @implemented
+ * copy it from wine 0.9.0 with small modifcations do check for NULL
*/
-char* _ultoa(unsigned long value, char* string, int radix)
+char* ultoa(unsigned long value, char* string, int radix)
{
- char tmp[33];
- char* tp = tmp;
- long i;
- unsigned long v = value;
- char* sp;
+ char buffer[33];
+ char *pos;
+ int digit;
+
+ pos = &buffer[32];
+ *pos = '\0';
- if (radix > 36 || radix <= 1)
- {
- __set_errno(EDOM);
- return 0;
- }
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ do {
+ digit = value % radix;
+ value = value / radix;
+ if (digit < 10) {
+ *--pos = '0' + digit;
+ } else {
+ *--pos = 'a' + digit - 10;
+ } /* if */
+ } while (value != 0L);
- while (v || tp == tmp)
- {
- i = v % radix;
- v = v / radix;
- if (i < 10)
- *tp++ = i+'0';
- else
- *tp++ = i + 'a' - 10;
- }
-
- if (string == 0)
- string = (char*)malloc((tp-tmp)+1);
- sp = string;
-
- while (tp > tmp)
- *sp++ = *--tp;
- *sp = 0;
- return string;
+ memcpy(string, pos, &buffer[32] - pos + 1);
+ return string;
}
Modified: trunk/reactos/lib/string/itoa.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/string/itoa.c?rev=21967…
==============================================================================
--- trunk/reactos/lib/string/itoa.c (original)
+++ trunk/reactos/lib/string/itoa.c Sun May 21 22:54:21 2006
@@ -133,35 +133,35 @@
/*
- * @implemented
+ * @implemented
+ * copy it from wine 0.9.0 with small modifcations do check for NULL
*/
char *
_ultoa(unsigned long value, char *string, int radix)
{
- char tmp[33];
- char *tp = tmp;
- long i;
- unsigned long v = value;
- char *sp;
+ char buffer[33];
+ char *pos;
+ int digit;
+
+ pos = &buffer[32];
+ *pos = '\0';
- if (radix > 36 || radix <= 1)
- {
- return 0;
- }
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ do {
+ digit = value % radix;
+ value = value / radix;
+ if (digit < 10) {
+ *--pos = '0' + digit;
+ } else {
+ *--pos = 'a' + digit - 10;
+ } /* if */
+ } while (value != 0L);
- while (v || tp == tmp)
- {
- i = v % radix;
- v = v / radix;
- if (i < 10)
- *tp++ = i+'0';
- else
- *tp++ = i + 'a' - 10;
- }
-
- sp = string;
- while (tp > tmp)
- *sp++ = *--tp;
- *sp = 0;
- return string;
+ memcpy(string, pos, &buffer[32] - pos + 1);
+
+ return string;
}