diff options
| author | KonAki <konaki@anokonaki.org> | 2026-10-13 15:32:52 +0800 |
|---|---|---|
| committer | KonAki <konaki@anokonaki.org> | 2026-10-13 15:32:52 +0800 |
| commit | 34e8cdac91c8b7ea955957f2f2ab025b689d16fd (patch) | |
| tree | e4d0a8434733bce0c58eb76002d4ae0cc4db6c25 /kon/konjson.h | |
| parent | e0442fcf511fd387b740661d28d824f9399d9bcb (diff) | |
konjson: allocate strings by their own length
Diffstat (limited to 'kon/konjson.h')
| -rw-r--r-- | kon/konjson.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/kon/konjson.h b/kon/konjson.h index 1e95990..126736d 100644 --- a/kon/konjson.h +++ b/kon/konjson.h @@ -166,13 +166,16 @@ static int kon__jsonUtf8(char *out, unsigned cp) static char *kon__jsonString(kon_jsonParser_t *ps) { - const char *start; + const char *start, *scan; char *out; size_t n = 0; ps->p++; start = ps->p; - out = malloc((size_t)(ps->end - start) + 1); + for (scan = start; scan < ps->end && *scan != '"'; scan++) { + if (*scan == '\\' && scan + 1 < ps->end) scan++; + } + out = malloc((size_t)(scan - start) + 1); if (!out) { kon__jsonFail(ps, "out of memory"); return NULL; |
