shithub: riscv

Download patch

ref: 983413de75dafe1794f131274bc18c5e30429e51
parent: f0483642be7ab5663daca6784f39e593d3e53ea2
author: BurnZeZ <brz-9dev@intma.in>
date: Sat Nov 9 22:35:25 EST 2013

libjson: don't perform chartorune in getch() when char is null terminator, and remove empty string check added last commit

--- a/sys/src/libjson/json.c
+++ b/sys/src/libjson/json.c
@@ -36,6 +36,8 @@
 		l->peeked = 0;
 		return r;
 	}
+	if(l->s[0] == '\0')
+		return 0;
 	l->s += chartorune(&r, l->s);
 	return r;
 }
@@ -318,11 +320,8 @@
 
 	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);
--