Add QJSON patch

pull/2171/merge
Ivan Romanov 6 years ago committed by Tony Theodore
parent 8730bed066
commit 2b31fc5791

@ -0,0 +1,78 @@
This file is part of MXE. See LICENSE.md for licensing information.
This patch has been taken from: https://github.com/flavio/qjson/issues/48#ref-pullrequest-345139226
From b5c5731794b3a882e9dd3c523eab2d1fd53948a6 Mon Sep 17 00:00:00 2001
From: Ivan Romanov <drizt@land.ru>
Date: Fri, 27 Jul 2018 13:32:18 +0500
Subject: [PATCH] Fix numbers parsing
strtoll and strtoull may not reset errno for valid input.
Need to check actual returned value as sayed in strtoll
documentation.
Fix #48
---
src/json_scanner.cc | 10 ++++++----
src/json_scanner.yy | 10 ++++++----
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/json_scanner.cc b/src/json_scanner.cc
index 58f7d00..5995af5 100644
--- a/src/json_scanner.cc
+++ b/src/json_scanner.cc
@@ -3393,8 +3393,9 @@ YY_RULE_SETUP
#line 82 "json_scanner.yy"
{
m_yylloc->columns(yyleng);
- *m_yylval = QVariant(strtoull(yytext, NULL, 10));
- if (errno == ERANGE) {
+ unsigned long long val = strtoull(yytext, NULL, 10);
+ *m_yylval = QVariant(val);
+ if (val == ULLONG_MAX && errno == ERANGE) {
qCritical() << "Number is out of range: " << yytext;
return yy::json_parser::token::INVALID;
}
@@ -3408,8 +3409,9 @@ YY_RULE_SETUP
#line 93 "json_scanner.yy"
{
m_yylloc->columns(yyleng);
- *m_yylval = QVariant(strtoll(yytext, NULL, 10));
- if (errno == ERANGE) {
+ long long val = strtoll(yytext, NULL, 10);
+ *m_yylval = QVariant(val);
+ if ((val == LLONG_MAX || val == LLONG_MIN) && errno == ERANGE) {
qCritical() << "Number is out of range: " << yytext;
return yy::json_parser::token::INVALID;
}
diff --git a/src/json_scanner.yy b/src/json_scanner.yy
index bc490d4..3000395 100644
--- a/src/json_scanner.yy
+++ b/src/json_scanner.yy
@@ -81,8 +81,9 @@ null {
[0-9] |
[1-9][0-9]+ {
m_yylloc->columns(yyleng);
- *m_yylval = QVariant(strtoull(yytext, NULL, 10));
- if (errno == ERANGE) {
+ unsigned long long val = strtoull(yytext, NULL, 10);
+ *m_yylval = QVariant(val);
+ if (val == ULLONG_MAX && errno == ERANGE) {
qCritical() << "Number is out of range: " << yytext;
return yy::json_parser::token::INVALID;
}
@@ -92,8 +93,9 @@ null {
-[0-9] |
-[1-9][0-9]+ {
m_yylloc->columns(yyleng);
- *m_yylval = QVariant(strtoll(yytext, NULL, 10));
- if (errno == ERANGE) {
+ long long val = strtoll(yytext, NULL, 10);
+ *m_yylval = QVariant(val);
+ if ((val == LLONG_MAX || val == LLONG_MIN) && errno == ERANGE) {
qCritical() << "Number is out of range: " << yytext;
return yy::json_parser::token::INVALID;
}
--
2.17.1
Loading…
Cancel
Save