diff options
-rw-r--r-- | lex.c | 14 | ||||
-rwxr-xr-x | testdir/T.misc | 14 |
2 files changed, 23 insertions, 5 deletions
@@ -421,8 +421,12 @@ int string(void) { int i; + if (!isxdigit(peek())) { + unput(c); + break; + } n = 0; - for (i = 1; i <= 2; i++) { + for (i = 0; i < 2; i++) { c = input(); if (c == 0) break; @@ -433,13 +437,13 @@ int string(void) n += (c - '0'); else n += 10 + (c - 'a'); - } else + } else { + unput(c); break; + } } - if (n) + if (i) *bp++ = n; - else - unput(c); break; } diff --git a/testdir/T.misc b/testdir/T.misc index 1e5c3c5..a2c0fb8 100755 --- a/testdir/T.misc +++ b/testdir/T.misc @@ -510,3 +510,17 @@ cmp -s foo1 foo2 || echo 'BAD: T.misc exit status on I/O error' echo 1b >foo1 echo ab | $awk '{ sub(/a/, "b" ~ /b/); print }' >foo2 cmp -s foo1 foo2 || echo 'BAD: T.misc lexer regex buffer clobbered' + ++# Check handling of octal (\OOO) and hex (\xHH) esc. seqs. in strings. ++echo 'hello888 ++hello ++hello ++helloxGOO ++hello ++0A' > foo1 ++$awk 'BEGIN { print "hello\888" }' > foo2 ++$awk 'BEGIN { print "hello\x000A" }' >> foo2 ++$awk 'BEGIN { printf "hello\x0A" }' >> foo2 ++$awk 'BEGIN { print "hello\xGOO" }' >> foo2 ++$awk 'BEGIN { print "hello\x0A0A" }' >> foo2 ++cmp -s foo1 foo2 || echo '�BAD: T.misc escape sequences in strings mishandled' |