Skip to content

Commit

Permalink
Recognize E along with e as exponent character in asciiToDouble
Browse files Browse the repository at this point in the history
Fixed a misguided condition in the check for bogus texts in the sscanf
branch of the decoder; it checked for 'e' but neglected 'E', which is
just as valid.

Change-Id: I9236c76faea000c92df641930e401bce445e06c8
Reviewed-by: Ulf Hermann <[email protected]>
  • Loading branch information
ediosyncratic committed Nov 23, 2018
1 parent ce159d1 commit d8b4019
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/corelib/tools/qlocale_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ double asciiToDouble(const char *num, int numLen, bool &ok, int &processed,
ok = false;
for (int i = 0; i < processed; ++i) {
char c = num[i];
if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e') {
if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e' && c != 'E') {
// Garbage found
processed = 0;
return 0.0;
Expand Down
2 changes: 2 additions & 0 deletions tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ void tst_QLocale::toReal_data()
QTest::newRow("C 1.234e-10") << QString("C") << QString("1.234e-10") << true << 1.234e-10;
QTest::newRow("C 1.234E10") << QString("C") << QString("1.234E10") << true << 1.234e10;
QTest::newRow("C 1e10") << QString("C") << QString("1e10") << true << 1.0e10;
QTest::newRow("C 1e310") << QString("C") << QString("1e310") << false << std::numeric_limits<double>::infinity();
QTest::newRow("C 1E310") << QString("C") << QString("1E310") << false << std::numeric_limits<double>::infinity();
QTest::newRow("C 1") << QString("C") << QString(" 1") << true << 1.0;
QTest::newRow("C 1") << QString("C") << QString(" 1") << true << 1.0;
QTest::newRow("C 1 ") << QString("C") << QString("1 ") << true << 1.0;
Expand Down

0 comments on commit d8b4019

Please sign in to comment.