Usermode/libc - Fixed buggy strtoi code
authorJohn Hodge <[email protected]>
Fri, 4 Oct 2013 13:10:32 +0000 (21:10 +0800)
committerJohn Hodge <[email protected]>
Fri, 4 Oct 2013 13:10:32 +0000 (21:10 +0800)
Usermode/Libraries/libc.so_src/EXP_strtoi.txt [new file with mode: 0644]
Usermode/Libraries/libc.so_src/TEST_strtoi.c [new file with mode: 0644]
Usermode/Libraries/libc.so_src/strtoi.c

diff --git a/Usermode/Libraries/libc.so_src/EXP_strtoi.txt b/Usermode/Libraries/libc.so_src/EXP_strtoi.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Usermode/Libraries/libc.so_src/TEST_strtoi.c b/Usermode/Libraries/libc.so_src/TEST_strtoi.c
new file mode 100644 (file)
index 0000000..5a8bf7c
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Acess2 C Library (Test)
+ * - By John Hodge (thePowersGang)
+ *
+ * TEST_strtoi.c
+ * - Tests for strtoi.c
+ */
+#include <stdio.h>
+
+#define TST(t, class, base, val, exp, fmt) do {\
+       t ret = strto##class(#val, NULL, base); \
+       if( ret != exp ) \
+               printf("FAIL strto"#class"('"#val"') != "#val" (act 0x"fmt")\n", ret);\
+}while(0)
+
+int main(int argc, char *argv[])
+{
+       TST(unsigned long, ul, 0, 0x10ec, 0x10ec, "%x");
+}
index 758906f..de7f725 100644 (file)
@@ -54,9 +54,9 @@ unsigned long long strtoull(const char *str, char **end, int base)
                        if( '0' <= *str && *str <= '9' )
                                next = *str - '0';
                        if( 'A' <= *str && *str <= 'A'+base-10-1 )
-                               next = *str - 'A';
+                               next = *str - 'A' + 10;
                        if( 'a' <= *str && *str <= 'a'+base-10-1 )
-                               next = *str - 'a';
+                               next = *str - 'a' + 10;
                }
                if( next < 0 )
                        break;

UCC git Repository :: git.ucc.asn.au