summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 e19a63fe1a..c42fa645c3 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -3541,7 +3541,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 2419cb4e29..e34cc1c947 100644
--- a/src/corelib/text/qlocale_tools.cpp
+++ b/src/corelib/text/qlocale_tools.cpp
@@ -39,7 +39,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) {
@@ -93,7 +94,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
@@ -595,7 +601,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 077218634d..2f676eced5 100644
--- a/src/corelib/text/qlocale_tools_p.h
+++ b/src/corelib/text/qlocale_tools_p.h
@@ -29,7 +29,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);