summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2017-04-11 02:16:22 +0800
committerWill Estes <westes575@gmail.com>2017-05-02 15:14:25 -0400
commit47d6a453457f0c33f9fd0c4e45ada1d5bb1e20ca (patch)
tree3f306e64a0abc796aadfa70df83a557a372acb25
parentd4ab90f185e18328b834cb80886b5be15f1019fe (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.c14
1 files changed, 5 insertions, 9 deletions
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<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';