]> granicus.if.org Git - flex/commitdiff
Fix myesc() 'sptr' conditionals
authorExplorer09 <explorer09@gmail.com>
Mon, 10 Apr 2017 18:16:22 +0000 (02:16 +0800)
committerWill Estes <westes575@gmail.com>
Tue, 2 May 2017 19:14:25 +0000 (15:14 -0400)
* 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<hex>" (<hex> is at most 2 digits)

src/misc.c

index d5d6b89b7c44219b7f31b8513b139e23b0626e89..cb7dba4cff055687289effacd0a4578dc4a56584 100644 (file)
@@ -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<hex> */
                        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';