diff options
author | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2021-08-11 17:08:02 +0200 |
---|---|---|
committer | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2021-08-16 11:45:14 +0200 |
commit | 864ecea83b7fd993d518d9a2c6c2d64710aed6f0 (patch) | |
tree | 757aa0e706b1583c4531cda012f64013204aa6c6 | |
parent | dc9075554135160bb07aa54708aba69d127160e2 (diff) |
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 <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/io/qurlidna.cpp | 14 |
1 files 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; } } |