aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chambers <[email protected]>2021-10-08 15:08:08 +1300
committerAndrew Chambers <[email protected]>2021-10-08 15:08:08 +1300
commite8fdb5043d8de0921d06a054b780c8254145e11d (patch)
tree789e0d96bc756ef5be6a356404ce5dece5f87014
parentab551328e2542f65b1fbee9df479c5b4957c8c9f (diff)
More error checking in hex literals.
-rw-r--r--main.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/main.c b/main.c
index 0ccc6a9..5725569 100644
--- a/main.c
+++ b/main.c
@@ -146,6 +146,7 @@ static Parsev *dupv(Parsev *p) {
static String decodestring(char *s) {
int i;
+ char *end;
size_t len = 0;
size_t cap = 0;
uint8_t *data = NULL;
@@ -156,13 +157,16 @@ static String decodestring(char *s) {
if (!*s) {
lfatal("bad escape in string");
} else if (*s >= '0' && *s <= '7') {
- char *end;
c = strtoul(s, &end, 8);
s += 3;
if (s != end)
lfatal("invalid octal sequence");
} else if (*s == 'x') {
- lfatal("TODO hex escape");
+ s++;
+ c = strtoul(s, &end, 16);
+ if (s == end)
+ lfatal("invalid hex sequence");
+ s = end;
} else {
c = *s;
s++;