diff options
author | Michael Forney <mforney@mforney.org> | 2021-10-20 14:03:59 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2021-10-20 14:42:42 -0700 |
commit | c8c9eac8c705a1677c306d94ab05459a593e3e1a (patch) | |
tree | ccdafd48def7459d9b9653f611cc887c5cc22d1c | |
parent | 77cc546cba247149a0beec7fae66521a61fdecfe (diff) |
expr: Fix octal escapes followed by octal digits
-rw-r--r-- | expr.c | 6 | ||||
-rw-r--r-- | test/string-octal.c | 1 | ||||
-rw-r--r-- | test/string-octal.qbe | 2 |
3 files changed, 7 insertions, 2 deletions
@@ -364,6 +364,7 @@ decodechar(const char *src, uint_least32_t *chr, bool *hexoct, const char *desc, { uint_least32_t c; size_t n; + int i; const char *s = src; if (*s == '\\') { @@ -392,8 +393,9 @@ decodechar(const char *src, uint_least32_t *chr, bool *hexoct, const char *desc, default: assert(isodigit(*s)); c = 0; - do c = c * 8 + (*s - '0'); - while (isodigit(*++s)); + i = 0; + do c = c * 8 + (*s++ - '0'); + while (++i < 3 && isodigit(*s)); if (hexoct) *hexoct = true; } diff --git a/test/string-octal.c b/test/string-octal.c new file mode 100644 index 0000000..85347fd --- /dev/null +++ b/test/string-octal.c @@ -0,0 +1 @@ +char *s = "\1\12\123\1234"; diff --git a/test/string-octal.qbe b/test/string-octal.qbe new file mode 100644 index 0000000..f4090fa --- /dev/null +++ b/test/string-octal.qbe @@ -0,0 +1,2 @@ +data $.Lstring.1 = align 1 { b "\001\012SS4\000", } +export data $s = align 8 { l $.Lstring.1, } |