diff --git a/be/src/util/jsonb_parser.h b/be/src/util/jsonb_parser.h index c050fd305c60947..5755788f1199a7e 100644 --- a/be/src/util/jsonb_parser.h +++ b/be/src/util/jsonb_parser.h @@ -62,6 +62,8 @@ #include #include +#include "string_parser.hpp" + #include "jsonb_document.h" #include "jsonb_error.h" #include "jsonb_writer.h" @@ -894,8 +896,11 @@ class JsonbParserT { } *pbuf = 0; // set null-terminator - int64_t val = strtol(num_buf_, NULL, 10); - if (errno == ERANGE) { + StringParser::ParseResult parse_result = StringParser::PARSE_SUCCESS; + int64_t val = StringParser::string_to_int(num_buf_, pbuf - num_buf_, &parse_result); + if (parse_result != StringParser::PARSE_SUCCESS) { + VLOG_ROW << "debug string_to_int error for " << num_buf_ + << " val=" << val << " parse_result=" << parse_result; err_ = JsonbErrType::E_DECIMAL_OVERFLOW; return false; } @@ -950,7 +955,7 @@ class JsonbParserT { } *pbuf = 0; // set null-terminator - return internConvertBufferToDouble(); + return internConvertBufferToDouble(num_buf_, pbuf - num_buf_); } // parse the exponent part of a double number @@ -990,15 +995,17 @@ class JsonbParserT { } *pbuf = 0; // set null-terminator - return internConvertBufferToDouble(); + return internConvertBufferToDouble(num_buf_, pbuf - num_buf_); } // call system function to parse double to string - bool internConvertBufferToDouble() { - double val = strtod(num_buf_, NULL); - - if (errno == ERANGE) { - err_ = JsonbErrType::E_DOUBLE_OVERFLOW; + bool internConvertBufferToDouble(char *num_buf_, int len) { + StringParser::ParseResult parse_result = StringParser::PARSE_SUCCESS; + double val = StringParser::string_to_float(num_buf_, len, &parse_result); + if (parse_result != StringParser::PARSE_SUCCESS) { + VLOG_ROW << "debug string_to_float error for " << num_buf_ + << " val=" << val << " parse_result=" << parse_result; + err_ = JsonbErrType::E_DECIMAL_OVERFLOW; return false; }