From 2b31fc5791d93a3feca480a687e367279fe6ab9a Mon Sep 17 00:00:00 2001 From: Ivan Romanov Date: Mon, 30 Jul 2018 08:33:23 +0500 Subject: [PATCH] Add QJSON patch --- src/qjson-2-numbers.patch | 78 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/qjson-2-numbers.patch diff --git a/src/qjson-2-numbers.patch b/src/qjson-2-numbers.patch new file mode 100644 index 00000000..1939bcf0 --- /dev/null +++ b/src/qjson-2-numbers.patch @@ -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 +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 +