]> git.lizzy.rs Git - plan9front.git/commitdiff
libjson: don't perform chartorune in getch() when char is null terminator, and remove...
authorBurnZeZ <brz-9dev@intma.in>
Sun, 10 Nov 2013 08:35:25 +0000 (03:35 -0500)
committerBurnZeZ <brz-9dev@intma.in>
Sun, 10 Nov 2013 08:35:25 +0000 (03:35 -0500)
sys/src/libjson/json.c

index 8d9b7bd91642e319421880c915cf27f3e3c54480..4a671c4e5a8991b7825f2cdee3b8bf4c3753f3e1 100644 (file)
@@ -36,6 +36,8 @@ getch(Lex *l)
                l->peeked = 0;
                return r;
        }
+       if(l->s[0] == '\0')
+               return 0;
        l->s += chartorune(&r, l->s);
        return r;
 }
@@ -318,11 +320,8 @@ jsonparse(char *s)
 
        memset(&l, 0, sizeof(l));
        l.s = s;
-       if((l.slen = strlen(s)) == 0){
-               werrstr("empty string");
-               return nil;
-       }
-       if((l.buf = mallocz(l.slen, 1)) == nil)
+       l.slen = strlen(s);
+       if((l.buf = mallocz(l.slen+1, 1)) == nil)
                return nil;
 
        j = jsonobj(&l);