From ee947e38400ef0df8104d8fb057638d38a178dfe Mon Sep 17 00:00:00 2001 From: IgorA Date: Thu, 30 Dec 2021 16:45:04 +0000 Subject: [PATCH] fix 'sscanf' by vitalkrilov git-svn-id: svn://kolibrios.org@9529 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../trunk/libc.obj/source/stdio/format_scan.c | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdio/format_scan.c b/programs/develop/ktcc/trunk/libc.obj/source/stdio/format_scan.c index 4c04752c20..ed4af0bb38 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdio/format_scan.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdio/format_scan.c @@ -171,16 +171,25 @@ int try_parse_int(long long *digit, int ch, const void *src, void *save, vir if (ch == '0') // octal or hex, read next { - base = 8; ch = vgetc(save, src); - if (ch == EOF || isspace(ch)) + if (ch == 'c' || ch == 'C') + base = 8; + else if (ch == 'x' || ch == 'X') + base = 16; + if (base == 10) have_digits++; else - if (ch == 'x' || ch == 'X') { - base = 16; - ch = vgetc(save, src); - if (ch == EOF) return EOF; + char tch = vgetc(save, src); + if ((base == 8 && isdigit(tch) && tch < '8') || + (base == 16 && isxdigit(tch))) + ch = tch; + else + { + have_digits++; + //base = 10; // not required: zero is zero with any (base > 1) + vungetc(save, tch, src); + } } } *digit = 0; @@ -193,7 +202,7 @@ int try_parse_int(long long *digit, int ch, const void *src, void *save, vir { if (base == 16) { - if (ch <= '9') ch-= '0'; + if (ch <= '9') ch -= '0'; else if (ch <= 'F') ch = 10 + ch - 'A'; else