summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-07-20 12:27:16 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-05 17:29:26 +0000
commitf83865f119fd312d137a020f6e6fd11f215f4cfd (patch)
tree84a8ab160c5049d1a36e3a35d2b34d251f26af57
parent830dc40cd063f1db67c06a360de43bd2e2972b29 (diff)
Port qt_doubleToAscii to qsizetype
Allows central handling of large buffers. Adjust some callers. Task-number: QTBUG-103531 Change-Id: Ib55974c3de250883cd0f6d11a7eee051c7fd11bc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit bd43c245e8c641c3a5c86762647f99658167b4db) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/text/qlocale.cpp2
-rw-r--r--src/corelib/text/qlocale_tools.cpp12
-rw-r--r--src/corelib/text/qlocale_tools_p.h3
3 files changed, 12 insertions, 5 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 73ceecb627..9e689a4fd0 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -3567,7 +3567,7 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form,
width = 0;
int decpt;
- int bufSize = 1;
+ qsizetype bufSize = 1;
if (precision == QLocale::FloatingPointShortest)
bufSize += std::numeric_limits<double>::max_digits10;
else if (form == DFDecimal && qIsFinite(d))
diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp
index 516377c5c5..ccfcbcfa5a 100644
--- a/src/corelib/text/qlocale_tools.cpp
+++ b/src/corelib/text/qlocale_tools.cpp
@@ -75,7 +75,8 @@ QT_BEGIN_NAMESPACE
QT_CLOCALE_HOLDER
-void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, char *buf, int bufSize,
+void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision,
+ char *buf, qsizetype bufSize,
bool &sign, int &length, int &decpt)
{
if (bufSize == 0) {
@@ -129,7 +130,12 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, cha
} else {
mode = double_conversion::DoubleToStringConverter::FIXED;
}
- double_conversion::DoubleToStringConverter::DoubleToAscii(d, mode, precision, buf, bufSize,
+ // libDoubleConversion is limited to 32-bit lengths. It's ok to cap the buffer size,
+ // though, because the library will never write 2GiB of chars as output
+ // (the length out-parameter is just an int, too).
+ const auto boundedBufferSize = static_cast<int>((std::min)(bufSize, qsizetype(INT_MAX)));
+ double_conversion::DoubleToStringConverter::DoubleToAscii(d, mode, precision, buf,
+ boundedBufferSize,
&sign, &length, &decpt);
#else // QT_NO_DOUBLECONVERSION || QT_BOOTSTRAPPED
@@ -619,7 +625,7 @@ QString qdtoa(qreal d, int *decpt, int *sign)
int length = 0;
// Some versions of libdouble-conversion like an extra digit, probably for '\0'
- constexpr int digits = std::numeric_limits<double>::max_digits10 + 1;
+ constexpr qsizetype digits = std::numeric_limits<double>::max_digits10 + 1;
char result[digits];
qt_doubleToAscii(d, QLocaleData::DFSignificantDigits, QLocale::FloatingPointShortest,
result, digits, nonNullSign, length, nonNullDecpt);
diff --git a/src/corelib/text/qlocale_tools_p.h b/src/corelib/text/qlocale_tools_p.h
index a4dbcf209b..27d5cdfd78 100644
--- a/src/corelib/text/qlocale_tools_p.h
+++ b/src/corelib/text/qlocale_tools_p.h
@@ -65,7 +65,8 @@ enum StrayCharacterMode {
// API note: this function can't process a number with more than 2.1 billion digits
[[nodiscard]] double qt_asciiToDouble(const char *num, qsizetype numLen, bool &ok, int &processed,
StrayCharacterMode strayCharMode = TrailingJunkProhibited);
-void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, char *buf, int bufSize,
+void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision,
+ char *buf, qsizetype bufSize,
bool &sign, int &length, int &decpt);
[[nodiscard]] QString qulltoBasicLatin(qulonglong l, int base, bool negative);