QLocale: use qsnprintf instead of deprecated sprintf

Fixes warnings such as

 qtbase/src/corelib/text/qlocale_tools.cpp:321:5: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]

from AppleClang.

Change-Id: Ief10e99abfa0a56c24622ac79db719dde58a4210
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 2e9bc3494f62761660e6ae9b5cc6caa0e170ca9a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-06-08 14:02:48 +02:00 committed by Qt Cherry-pick Bot
parent e737c163b0
commit 1f3529d8e8

View File

@ -318,7 +318,7 @@ double qt_asciiToDouble(const char *num, qsizetype numLen, bool &ok, int &proces
constexpr auto maxDigitsForULongLong = 1 + std::numeric_limits<unsigned long long>::digits10;
// need to ensure that we don't read more than numLen of input:
char fmt[1 + maxDigitsForULongLong + 4 + 1];
sprintf(fmt, "%s%llu%s", "%", static_cast<unsigned long long>(numLen), "lf%n");
qsnprintf(fmt, sizeof fmt, "%s%llu%s", "%", static_cast<unsigned long long>(numLen), "lf%n");
if (qDoubleSscanf(num, QT_CLOCALE, fmt, &d, &processed) < 1)
processed = 0;