From 795e7dd091aa51141e7a907940b2d56eec0bc526 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 16 Dec 2021 06:53:33 +0100 Subject: [PATCH] QString: scope a loop variable correctly The variable idx isn't used outside the respective loops, so make it loop-local. Change-Id: I62807cb244b068ce4df42812a0e4b99a1f488adc Reviewed-by: Sona Kurazyan Reviewed-by: Anton Kudryavtsev --- src/corelib/text/qstring.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index fe9585c607..4d6e4386f4 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -10484,10 +10484,9 @@ static qsizetype qLastIndexOf(Haystack haystack0, qsizetype from, const auto *n = needle + sl_minus_1; const auto *h = haystack + sl_minus_1; std::size_t hashNeedle = 0, hashHaystack = 0; - qsizetype idx; if (cs == Qt::CaseSensitive) { - for (idx = 0; idx < sl; ++idx) { + for (qsizetype idx = 0; idx < sl; ++idx) { hashNeedle = (hashNeedle << 1) + valueTypeToUtf16(*(n - idx)); hashHaystack = (hashHaystack << 1) + valueTypeToUtf16(*(h - idx)); } @@ -10502,7 +10501,7 @@ static qsizetype qLastIndexOf(Haystack haystack0, qsizetype from, REHASH(valueTypeToUtf16(haystack[sl])); } } else { - for (idx = 0; idx < sl; ++idx) { + for (qsizetype idx = 0; idx < sl; ++idx) { hashNeedle = (hashNeedle << 1) + foldCaseHelper(n - idx, needle); hashHaystack = (hashHaystack << 1) + foldCaseHelper(h - idx, end); }