diff options
author | BurnZeZ <brz-9dev@intma.in> | 2013-10-28 23:21:07 -0400 |
---|---|---|
committer | BurnZeZ <brz-9dev@intma.in> | 2013-10-28 23:21:07 -0400 |
commit | a8e8b650f3643c1a9f434fb2efb4708ff53539cd (patch) | |
tree | 2eef1c6a516222899093ccc8232cc7451d0841a9 /sys/src/libjson | |
parent | 82f4c1c0b4160672467e5eceea4c6f7a48c9481c (diff) |
libjson: dynamically allocate buffer
Diffstat (limited to 'sys/src/libjson')
-rw-r--r-- | sys/src/libjson/json.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/sys/src/libjson/json.c b/sys/src/libjson/json.c index 1056ac5d0..1cf77be3b 100644 --- a/sys/src/libjson/json.c +++ b/sys/src/libjson/json.c @@ -17,9 +17,10 @@ enum { struct Lex { char *s; + ulong slen; int t; double n; - char buf[4096]; + char *buf; Rune peeked; jmp_buf jmp; int canjmp; @@ -96,7 +97,7 @@ lex(Lex *l) t = l->buf; for(;;){ t += runetochar(t, &r); - if(t >= l->buf + sizeof(l->buf)){ + if(t >= l->buf + l->slen){ werrstr("json: literal too long"); return -1; } @@ -181,7 +182,7 @@ lex(Lex *l) } r2 = 0; t += runetochar(t, &r); - if(t >= l->buf + sizeof(l->buf)){ + if(t >= l->buf + l->slen){ werrstr("json: string too long"); return -1; } @@ -201,7 +202,11 @@ jsonobj(Lex *l) JSONEl *e; JSONEl **ln; int obj; - + + l->buf = mallocz(l->slen, 1); + if(l->buf == nil) + return nil; + j = mallocz(sizeof(*j), 1); if(j == nil) return nil; @@ -319,6 +324,7 @@ jsonparse(char *s) memset(&l, 0, sizeof(l)); l.s = s; + l.slen = strlen(s)+1; return jsonobj(&l); } |