From: John Hodge Date: Fri, 4 Oct 2013 13:10:32 +0000 (+0800) Subject: Usermode/libc - Fixed buggy strtoi code X-Git-Tag: rel0.15~144 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=bdd7f1f599b357218e219aeb2bd9264e6412d629;p=tpg%2Facess2.git Usermode/libc - Fixed buggy strtoi code --- diff --git a/Usermode/Libraries/libc.so_src/EXP_strtoi.txt b/Usermode/Libraries/libc.so_src/EXP_strtoi.txt new file mode 100644 index 00000000..e69de29b diff --git a/Usermode/Libraries/libc.so_src/TEST_strtoi.c b/Usermode/Libraries/libc.so_src/TEST_strtoi.c new file mode 100644 index 00000000..5a8bf7c5 --- /dev/null +++ b/Usermode/Libraries/libc.so_src/TEST_strtoi.c @@ -0,0 +1,19 @@ +/* + * Acess2 C Library (Test) + * - By John Hodge (thePowersGang) + * + * TEST_strtoi.c + * - Tests for strtoi.c + */ +#include + +#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"); +} diff --git a/Usermode/Libraries/libc.so_src/strtoi.c b/Usermode/Libraries/libc.so_src/strtoi.c index 758906fd..de7f7254 100644 --- a/Usermode/Libraries/libc.so_src/strtoi.c +++ b/Usermode/Libraries/libc.so_src/strtoi.c @@ -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;