Fixes issue 221 (#222)

https://github.com/lemire/simdjson/issues/221
This commit is contained in:
Daniel Lemire
2019-07-29 10:07:07 -04:00
committed by ioioioio
parent eba02dc1b9
commit f76ee5e5ef
5 changed files with 9 additions and 5 deletions
View File
+1
View File
@@ -0,0 +1 @@
-1
+5 -3
View File
@@ -35,9 +35,11 @@ ParsedJson::ParsedJson(ParsedJson && p)
WARN_UNUSED
bool ParsedJson::allocateCapacity(size_t len, size_t maxdepth) {
if ((maxdepth == 0) || (len == 0)) {
std::cerr << "capacities must be non-zero " << std::endl;
return false;
if (maxdepth <= 0) {
maxdepth = 1; // don't let the user allocate nothing
}
if (len <= 0) {
len = 64; // allocating 0 bytes is wasteful.
}
if(len > SIMDJSON_MAXSIZE_BYTES) {
return false;
+2 -2
View File
@@ -86,8 +86,8 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
int res = simdjson::json_parse(p, pj); // do the parsing, return false on error
if (res) {
std::cerr << " Parsing failed. " << std::endl;
if (res != simdjson::SUCCESS) {
std::cerr << " Parsing failed. Error is '" << simdjson::errorMsg(res) << "'." << std::endl;
return EXIT_FAILURE;
}
if (apidump) {
+1
View File
@@ -46,6 +46,7 @@ stat_t simdjson_computestats(const simdjson::padded_string &p) {
simdjson::ParsedJson pj = simdjson::build_parsed_json(p);
answer.valid = pj.isValid();
if (!answer.valid) {
std::cerr << pj.getErrorMsg() << std::endl;
return answer;
}
answer.backslash_count = count_backslash(reinterpret_cast<const uint8_t*>(p.data()), p.size());