diff options
author | Explorer09 <explorer09@gmail.com> | 2017-04-11 02:16:22 +0800 |
---|---|---|
committer | Will Estes <westes575@gmail.com> | 2017-05-02 15:14:25 -0400 |
commit | 47d6a453457f0c33f9fd0c4e45ada1d5bb1e20ca (patch) | |
tree | 3f306e64a0abc796aadfa70df83a557a372acb25 | |
parent | d4ab90f185e18328b834cb80886b5be15f1019fe (diff) |
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<hex>" (<hex> is at most 2 digits)
-rw-r--r-- | src/misc.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -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'; |