From fd1ac4f1791b403af1f7350b1195ac114f9b792b Mon Sep 17 00:00:00 2001 From: Dave Gamble Date: Mon, 10 Oct 2011 15:33:19 +0000 Subject: [PATCH] make parse_number more robust! git-svn-id: http://svn.code.sf.net/p/cjson/code@42 e3330c51-1366-4df0-8b21-3ccf24e3d50e --- cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 0e68a49..eb7c2f9 100644 --- a/cJSON.c +++ b/cJSON.c @@ -101,7 +101,7 @@ static const char *parse_number(cJSON *item,const char *num) if (*num=='-') sign=-1,num++; /* Has sign? */ if (*num=='0') num++; /* is zero */ if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */ - if (*num=='.') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */ + if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */ if (*num=='e' || *num=='E') /* Exponent? */ { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */ while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */