From: Explorer09 Date: Mon, 10 Apr 2017 18:16:22 +0000 (+0800) Subject: Fix myesc() 'sptr' conditionals X-Git-Tag: v2.6.4~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47d6a453457f0c33f9fd0c4e45ada1d5bb1e20ca;p=flex Fix myesc() 'sptr' conditionals * Don't call isascii() here. It's deprecated in POSIX and not needed for myesc's case. * The check of the character class and range here should match what's defined as {ESCSEQ} in scan.l, so for [[:xdigit:]] we use isxdigit(); for [0-7] we check '0' <= c <= '7' (not isdigit(c) because isdigit is locale-dependant in standard's sense) * Add missing length limit for "\x" ( is at most 2 digits) --- diff --git a/src/misc.c b/src/misc.c index d5d6b89..cb7dba4 100644 --- a/src/misc.c +++ b/src/misc.c @@ -505,13 +505,9 @@ unsigned char myesc (unsigned char array[]) int sptr = 1; while (sptr <= 3 && - isascii (array[sptr]) && - isdigit (array[sptr])) - /* Don't increment inside loop control - * because if isdigit() is a macro it might - * expand into multiple increments ... - */ + array[sptr] >= '0' && array[sptr] <= '7') { ++sptr; + } c = array[sptr]; array[sptr] = '\0'; @@ -527,13 +523,13 @@ unsigned char myesc (unsigned char array[]) { /* \x */ int sptr = 2; - while (isascii (array[sptr]) && - isxdigit (array[sptr])) + while (sptr <= 3 && isxdigit (array[sptr])) { /* Don't increment inside loop control - * because if isdigit() is a macro it might + * because if isxdigit() is a macro it might * expand into multiple increments ... */ ++sptr; + } c = array[sptr]; array[sptr] = '\0';