summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2023-12-15 23:41:20 -0500
committerFreya Murphy <freya@freyacat.org>2023-12-15 23:41:20 -0500
commit4760ed147e57fbf38fd0ecbbf7abaa41e9a751b9 (patch)
tree96f7e414698f8158eb6755aa83828a945a243c84
parentfix json fp precision, fix multi value json compound tags (diff)
downloadnbtvis-4760ed147e57fbf38fd0ecbbf7abaa41e9a751b9.tar.gz
nbtvis-4760ed147e57fbf38fd0ecbbf7abaa41e9a751b9.tar.bz2
nbtvis-4760ed147e57fbf38fd0ecbbf7abaa41e9a751b9.zip
fix hang on incomplete json ident
-rw-r--r--src/json/read.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/json/read.c b/src/json/read.c
index 1401633..ea6e106 100644
--- a/src/json/read.c
+++ b/src/json/read.c
@@ -170,30 +170,31 @@ static bool json_parse_string(tokendata_t *token, const stream_t *stream) {
return true;
}
-static bool json_parse_ident(token_t *token, const stream_t *stream, char first) {
-
- char buf[4];
- buf[3] = '\0';
-
- if (stream_read(stream, buf, 3) == false)
+static bool json_ident_assert(const stream_t *stream, const char *rest) {
+ char c;
+ if (stream_read(stream, &c, 1) == false)
+ return false;
+ if (c != *rest)
return false;
+ rest += 1;
+ if (*rest == '\0')
+ return true;
+ else
+ return json_ident_assert(stream, rest);
+}
- if (first == 't' && strcmp(buf, "rue") == 0) {
+static bool json_parse_ident(token_t *token, const stream_t *stream, char first) {
+ if (first == 't' && json_ident_assert(stream, "true")) {
token->type = TOK_BOOL;
token->data.b = true;
- } else if (first == 'f' && strcmp(buf, "als") == 0) {
- if (stream_read(stream, buf, 1) == false)
- return false;
- if (*buf != 'e')
- return false;
+ } else if (first == 'f' && json_ident_assert(stream, "alse")) {
token->type = TOK_BOOL;
token->data.b = false;
- } else if (first == 'n' && strcmp(buf, "ull") == 0) {
+ } else if (first == 'n' && json_ident_assert(stream, "ull")) {
token->type = TOK_NULL;
} else {
return false;
}
-
return true;
}