From 864ecea83b7fd993d518d9a2c6c2d64710aed6f0 Mon Sep 17 00:00:00 2001 From: Ievgenii Meshcheriakov Date: Wed, 11 Aug 2021 17:08:02 +0200 Subject: [PATCH] QUrl: Make Punycode encoding code less surprising Move the code that modifies the encoding loop variables from appendEncode() back to qt_punycodeEncoder() instead of passing the variables by reference. This gives better overview of how those variables change. Remove comment claiming overflow detection inside appendEncode() where no overflow detection is done. Task-number: QTBUG-95689 Pick-to: 6.2 Change-Id: I8830e75370646f0c9b78cae883f778a12e32919d Reviewed-by: Thiago Macieira --- src/corelib/io/qurlidna.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp index 5621fa83a3..1f369de895 100644 --- a/src/corelib/io/qurlidna.cpp +++ b/src/corelib/io/qurlidna.cpp @@ -2193,14 +2193,13 @@ static inline uint adapt(uint delta, uint numpoints, bool firsttime) return k + (((base - tmin + 1) * delta) / (delta + skew)); } -static inline void appendEncode(QString* output, uint& delta, uint& bias, uint& b, uint& h) +static inline void appendEncode(QString *output, uint delta, uint bias) { uint qq; uint k; uint t; - // insert the variable length delta integer; fail on - // overflow. + // insert the variable length delta integer. for (qq = delta, k = base;; k += base) { // stop generating digits when the threshold is // detected. @@ -2212,9 +2211,6 @@ static inline void appendEncode(QString* output, uint& delta, uint& bias, uint& } *output += QChar(encodeDigit(qq)); - bias = adapt(delta, h + 1, h == b); - delta = 0; - ++h; } Q_AUTOTEST_EXPORT void qt_punycodeEncoder(QStringView in, QString *output) @@ -2300,7 +2296,11 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(QStringView in, QString *output) // if j is the index of the character with the lowest // unicode code... if (c == n) { - appendEncode(output, delta, bias, b, h); + appendEncode(output, delta, bias); + + bias = adapt(delta, h + 1, h == b); + delta = 0; + ++h; } }