Skip to content

Commit

Permalink
Tweaks to JSON parser error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Dec 13, 2024
1 parent 6a02f43 commit 9655e5c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/xjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ static char UnescapedChar(char c) {
return c;
}

static int json2raw(const char *json, int maxlen, char *dst) {
static char *json2raw(const char *json, int maxlen, char *dst) {
int isEscaped = 0;
int i, l = 0;

Expand All @@ -602,7 +602,7 @@ static int json2raw(const char *json, int maxlen, char *dst) {
if(unicode <= 0xFF) dst[l++] = (char) unicode; // -> ASCII
else l += sprintf(&dst[l], "\\u%04hx", unicode); // -> keep as is
}
else Error("Unicode \\u without 4 digit hex");
else return "Unicode \\u without 4 digit hex";
}
else {
dst[l++] = UnescapedChar(c);
Expand All @@ -614,7 +614,7 @@ static int json2raw(const char *json, int maxlen, char *dst) {
}

dst[l] = '\0';
return l;
return NULL;
}

static char *ParseString(char **pos, int *lineNumber) {
Expand Down Expand Up @@ -658,7 +658,8 @@ static char *ParseString(char **pos, int *lineNumber) {
return NULL;
}

json2raw(next, l, dst);
next = json2raw(next, l, dst);
if(next) Error("[L.%d] %s.\n", *lineNumber, next);

return dst;
}
Expand Down Expand Up @@ -1371,6 +1372,8 @@ char *xjsonUnescape(const char *str) {
return NULL;
}

json2raw(str, l, raw);
str = json2raw(str, l, raw);
if(str) x_error(0, EBADE, fn, str);

return raw;
}

0 comments on commit 9655e5c

Please sign in to comment.