diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-07-20 12:27:16 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-07-26 02:06:17 +0200 |
commit | bd43c245e8c641c3a5c86762647f99658167b4db (patch) | |
tree | d3f7bd8ad6334e7ccc40300eedb9474678154731 /src/corelib/text | |
parent | ec35efd7f2cea4dcbe0188f0d44cde541803f53e (diff) |
Port qt_doubleToAscii to qsizetype
Allows central handling of large buffers.
Adjust some callers.
Pick-to: 6.4 6.3
Task-number: QTBUG-103531
Change-Id: Ib55974c3de250883cd0f6d11a7eee051c7fd11bc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 2 | ||||
-rw-r--r-- | src/corelib/text/qlocale_tools.cpp | 12 | ||||
-rw-r--r-- | src/corelib/text/qlocale_tools_p.h | 3 |
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); |