diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index e0d2fc3a5e7..b965e35175e 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -40,6 +40,7 @@ #include #endif #include +#include #include "qsimd_p.h" #include #include @@ -5885,13 +5886,17 @@ static uint parse_flag_characters(const char * &c) Q_DECL_NOTHROW static int parse_field_width(const char * &c) { - QString width_str; - while (*c != '\0' && qIsDigit(*c)) - width_str.append(QLatin1Char(*c++)); + Q_ASSERT(qIsDigit(*c)); // can't be negative - started with a digit // contains at least one digit - return width_str.toInt(); + const char *endp; + bool ok; + const qulonglong result = qstrtoull(c, &endp, 10, &ok); + c = endp; + while (qIsDigit(*c)) // preserve Qt 5.5 behavior of consuming all digits, no matter how many + ++c; + return ok && result < qulonglong(std::numeric_limits::max()) ? int(result) : 0; } /*!