Skip to content

Commit

Permalink
fix jsonb
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Dec 14, 2022
1 parent 1820929 commit aa3541e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions be/src/util/jsonb_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#include <cmath>
#include <limits>

#include "string_parser.hpp"

#include "jsonb_document.h"
#include "jsonb_error.h"
#include "jsonb_writer.h"
Expand Down Expand Up @@ -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<int64_t>(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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<double>(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;
}

Expand Down

0 comments on commit aa3541e

Please sign in to comment.