Number parsing fix.

This commit is contained in:
Daniel Lemire 2019-01-04 17:36:52 -05:00
parent bf652295eb
commit a00df9b992
4 changed files with 56 additions and 16 deletions

View File

@ -189,6 +189,17 @@ parse_float(const uint8_t *const buf,
if ('.' == *p) { if ('.' == *p) {
++p; ++p;
double fractionalweight = 1; double fractionalweight = 1;
if(is_integer(*p)) {
unsigned char digit = *p - '0';
++p;
fractionalweight *= 0.1;
i = i + digit * fractionalweight;
} else {
#ifdef JSON_TEST_NUMBERS // for unit testing
foundInvalidNumber(buf + offset);
#endif
return false;
}
while (is_integer(*p)) { while (is_integer(*p)) {
unsigned char digit = *p - '0'; unsigned char digit = *p - '0';
++p; ++p;
@ -389,7 +400,16 @@ static really_inline bool parse_number(const uint8_t *const buf,
if ('.' == *p) { if ('.' == *p) {
++p; ++p;
const char *const firstafterperiod = p; const char *const firstafterperiod = p;
if(is_integer(*p)) {
unsigned char digit = *p - '0';
++p;
i = i * 10 + digit;
} else {
#ifdef JSON_TEST_NUMBERS // for unit testing
foundInvalidNumber(buf + offset);
#endif
return false;
}
#ifdef SWAR_NUMBER_PARSING #ifdef SWAR_NUMBER_PARSING
// this helps if we have lots of decimals! // this helps if we have lots of decimals!
// this turns out to be frequent enough. // this turns out to be frequent enough.

View File

@ -1,4 +1,4 @@
/* auto-generated on Mon Dec 31 17:13:28 EST 2018. Do not edit! */ /* auto-generated on Fri Jan 4 17:36:46 EST 2019. Do not edit! */
#include <iostream> #include <iostream>
#include "simdjson.h" #include "simdjson.h"

View File

@ -1,4 +1,4 @@
/* auto-generated on Mon Dec 31 17:13:28 EST 2018. Do not edit! */ /* auto-generated on Fri Jan 4 17:36:46 EST 2019. Do not edit! */
#include "simdjson.h" #include "simdjson.h"
/* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */ /* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */
@ -814,8 +814,8 @@ WARN_UNUSED
return true; return true;
#endif #endif
} }
/* end file /Users/lemire/CVS/github/simdjson/src/stage1_find_marks.cpp */ /* end file /home/dlemire/CVS/github/simdjson/src/stage1_find_marks.cpp */
/* begin file /Users/lemire/CVS/github/simdjson/src/stage2_build_tape.cpp */ /* begin file /home/dlemire/CVS/github/simdjson/src/stage2_build_tape.cpp */
#ifdef _MSC_VER #ifdef _MSC_VER
/* Microsoft C/C++-compatible compiler */ /* Microsoft C/C++-compatible compiler */
#include <intrin.h> #include <intrin.h>
@ -1322,4 +1322,4 @@ succeed:
fail: fail:
return false; return false;
} }
/* end file /Users/lemire/CVS/github/simdjson/src/stage2_build_tape.cpp */ /* end file /home/dlemire/CVS/github/simdjson/src/stage2_build_tape.cpp */

View File

@ -1,5 +1,5 @@
/* auto-generated on Mon Dec 31 17:13:28 EST 2018. Do not edit! */ /* auto-generated on Fri Jan 4 17:36:46 EST 2019. Do not edit! */
/* begin file /Users/lemire/CVS/github/simdjson/include/simdjson/portability.h */ /* begin file /home/dlemire/CVS/github/simdjson/include/simdjson/portability.h */
#ifndef SIMDJSON_PORTABILITY_H #ifndef SIMDJSON_PORTABILITY_H
#define SIMDJSON_PORTABILITY_H #define SIMDJSON_PORTABILITY_H
@ -36515,8 +36515,8 @@ static inline bool find_structural_bits(const char *buf, size_t len, ParsedJson
} }
#endif #endif
/* end file /Users/lemire/CVS/github/simdjson/include/simdjson/stage1_find_marks.h */ /* end file /home/dlemire/CVS/github/simdjson/include/simdjson/stage1_find_marks.h */
/* begin file /Users/lemire/CVS/github/simdjson/include/simdjson/stringparsing.h */ /* begin file /home/dlemire/CVS/github/simdjson/include/simdjson/stringparsing.h */
#ifndef SIMDJSON_STRINGPARSING_H #ifndef SIMDJSON_STRINGPARSING_H
#define SIMDJSON_STRINGPARSING_H #define SIMDJSON_STRINGPARSING_H
@ -36627,7 +36627,7 @@ really_inline bool parse_string(const uint8_t *buf, UNUSED size_t len,
return is_ok; return is_ok;
#else //CHECKUNESCAPED #else //CHECKUNESCAPED
#ifdef JSON_TEST_STRINGS // for unit testing #ifdef JSON_TEST_STRINGS // for unit testing
foundString(buf + offset,start_of_string,pj.current_string_buf_loc); foundString(buf + offset,start_of_string,pj.current_string_buf_loc - 1);
#endif // JSON_TEST_STRINGS #endif // JSON_TEST_STRINGS
return true; return true;
#endif //CHECKUNESCAPED #endif //CHECKUNESCAPED
@ -36883,6 +36883,17 @@ parse_float(const uint8_t *const buf,
if ('.' == *p) { if ('.' == *p) {
++p; ++p;
double fractionalweight = 1; double fractionalweight = 1;
if(is_integer(*p)) {
unsigned char digit = *p - '0';
++p;
fractionalweight *= 0.1;
i = i + digit * fractionalweight;
} else {
#ifdef JSON_TEST_NUMBERS // for unit testing
foundInvalidNumber(buf + offset);
#endif
return false;
}
while (is_integer(*p)) { while (is_integer(*p)) {
unsigned char digit = *p - '0'; unsigned char digit = *p - '0';
++p; ++p;
@ -37083,7 +37094,16 @@ static really_inline bool parse_number(const uint8_t *const buf,
if ('.' == *p) { if ('.' == *p) {
++p; ++p;
const char *const firstafterperiod = p; const char *const firstafterperiod = p;
if(is_integer(*p)) {
unsigned char digit = *p - '0';
++p;
i = i * 10 + digit;
} else {
#ifdef JSON_TEST_NUMBERS // for unit testing
foundInvalidNumber(buf + offset);
#endif
return false;
}
#ifdef SWAR_NUMBER_PARSING #ifdef SWAR_NUMBER_PARSING
// this helps if we have lots of decimals! // this helps if we have lots of decimals!
// this turns out to be frequent enough. // this turns out to be frequent enough.
@ -37192,8 +37212,8 @@ static really_inline bool parse_number(const uint8_t *const buf,
} }
#endif #endif
/* end file /Users/lemire/CVS/github/simdjson/include/simdjson/numberparsing.h */ /* end file /home/dlemire/CVS/github/simdjson/include/simdjson/numberparsing.h */
/* begin file /Users/lemire/CVS/github/simdjson/include/simdjson/stage2_build_tape.h */ /* begin file /home/dlemire/CVS/github/simdjson/include/simdjson/stage2_build_tape.h */
#ifndef SIMDJSON_STAGE34_UNIFIED_H #ifndef SIMDJSON_STAGE34_UNIFIED_H
#define SIMDJSON_STAGE34_UNIFIED_H #define SIMDJSON_STAGE34_UNIFIED_H
@ -37209,8 +37229,8 @@ static inline bool unified_machine(const char *buf, size_t len, ParsedJson &pj)
} }
#endif #endif
/* end file /Users/lemire/CVS/github/simdjson/include/simdjson/stage2_build_tape.h */ /* end file /home/dlemire/CVS/github/simdjson/include/simdjson/stage2_build_tape.h */
/* begin file /Users/lemire/CVS/github/simdjson/include/simdjson/jsonparser.h */ /* begin file /home/dlemire/CVS/github/simdjson/include/simdjson/jsonparser.h */
#ifndef SIMDJSON_JSONPARSER_H #ifndef SIMDJSON_JSONPARSER_H
#define SIMDJSON_JSONPARSER_H #define SIMDJSON_JSONPARSER_H