Skip to content

Commit c1441ef

Browse files
datadiodecdunn2001
authored andcommitted
stricter float parsing
fixes `test/jsonchecker/fail31.json` (issue #113)
1 parent e0bfb45 commit c1441ef

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/lib_json/json_reader.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,24 @@ bool Reader::readCppStyleComment() {
381381
}
382382

383383
void Reader::readNumber() {
384-
while (current_ != end_) {
385-
if (!(*current_ >= '0' && *current_ <= '9') &&
386-
!in(*current_, '.', 'e', 'E', '+', '-'))
387-
break;
388-
++current_;
384+
const char *p = current_;
385+
char c = '0'; // stopgap for already consumed character
386+
// integral part
387+
while (c >= '0' && c <= '9')
388+
c = (current_ = p) < end_ ? *p++ : 0;
389+
// fractional part
390+
if (c == '.') {
391+
c = (current_ = p) < end_ ? *p++ : 0;
392+
while (c >= '0' && c <= '9')
393+
c = (current_ = p) < end_ ? *p++ : 0;
394+
}
395+
// exponential part
396+
if (c == 'e' || c == 'E') {
397+
c = (current_ = p) < end_ ? *p++ : 0;
398+
if (c == '+' || c == '-')
399+
c = (current_ = p) < end_ ? *p++ : 0;
400+
while (c >= '0' && c <= '9')
401+
c = (current_ = p) < end_ ? *p++ : 0;
389402
}
390403
}
391404

0 commit comments

Comments
 (0)