Port qt_repeatCount() to qsizetype
While it's true that the typical user of the function won't expect more than half a dozen repeats, this function is fed with user-supplied input, so it could be asked to return in excess of INT_MAX matches. The truncation then means we're misreporting the number mod INT_MAX, which is as good as a random number and leads to false positive matches in users of the function. Just return the true result instead of a truncated one. Task-number: QTBUG-103531 Change-Id: I5e3aa23dec873c6f9af255e90748fb38619d2f5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit d6b38be3dfa4579cbe99cc442452a45779a71e70) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f1324ccd89
commit
a0752a7f15
@ -668,7 +668,7 @@ QString qt_readEscapedFormatString(QStringView format, int *idx)
|
|||||||
qt_repeatCount(u"aab"); // == 2
|
qt_repeatCount(u"aab"); // == 2
|
||||||
\endcode
|
\endcode
|
||||||
*/
|
*/
|
||||||
int qt_repeatCount(QStringView s)
|
qsizetype qt_repeatCount(QStringView s)
|
||||||
{
|
{
|
||||||
if (s.isEmpty())
|
if (s.isEmpty())
|
||||||
return 0;
|
return 0;
|
||||||
@ -676,7 +676,7 @@ int qt_repeatCount(QStringView s)
|
|||||||
qsizetype j = 1;
|
qsizetype j = 1;
|
||||||
while (j < s.size() && s.at(j) == c)
|
while (j < s.size() && s.at(j) == c)
|
||||||
++j;
|
++j;
|
||||||
return int(j);
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_CONSTINIT static const QLocaleData *default_data = nullptr;
|
Q_CONSTINIT static const QLocaleData *default_data = nullptr;
|
||||||
@ -3333,7 +3333,7 @@ QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QChar c = format.at(i);
|
const QChar c = format.at(i);
|
||||||
int repeat = qt_repeatCount(format.mid(i));
|
qsizetype repeat = qt_repeatCount(format.mid(i));
|
||||||
bool used = false;
|
bool used = false;
|
||||||
if (formatDate) {
|
if (formatDate) {
|
||||||
switch (c.unicode()) {
|
switch (c.unicode()) {
|
||||||
|
@ -267,7 +267,7 @@ static QVariant macToQtFormat(QStringView sys_fmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QChar c = sys_fmt.at(i);
|
QChar c = sys_fmt.at(i);
|
||||||
int repeat = qt_repeatCount(sys_fmt.mid(i));
|
qsizetype repeat = qt_repeatCount(sys_fmt.mid(i));
|
||||||
|
|
||||||
switch (c.unicode()) {
|
switch (c.unicode()) {
|
||||||
// Qt does not support the following options
|
// Qt does not support the following options
|
||||||
|
@ -479,7 +479,7 @@ inline char QLocaleData::numericToCLocale(QStringView in) const
|
|||||||
QString qt_readEscapedFormatString(QStringView format, int *idx);
|
QString qt_readEscapedFormatString(QStringView format, int *idx);
|
||||||
[[nodiscard]] bool qt_splitLocaleName(QStringView name, QStringView *lang = nullptr,
|
[[nodiscard]] bool qt_splitLocaleName(QStringView name, QStringView *lang = nullptr,
|
||||||
QStringView *script = nullptr, QStringView *cntry = nullptr);
|
QStringView *script = nullptr, QStringView *cntry = nullptr);
|
||||||
[[nodiscard]] int qt_repeatCount(QStringView s);
|
[[nodiscard]] qsizetype qt_repeatCount(QStringView s);
|
||||||
|
|
||||||
enum { AsciiSpaceMask = (1u << (' ' - 1)) |
|
enum { AsciiSpaceMask = (1u << (' ' - 1)) |
|
||||||
(1u << ('\t' - 1)) | // 9: HT - horizontal tab
|
(1u << ('\t' - 1)) | // 9: HT - horizontal tab
|
||||||
|
@ -729,7 +729,7 @@ QString QSystemLocalePrivate::winToQtFormat(QStringView sys_fmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QChar c = sys_fmt.at(i);
|
QChar c = sys_fmt.at(i);
|
||||||
int repeat = qt_repeatCount(sys_fmt.mid(i));
|
qsizetype repeat = qt_repeatCount(sys_fmt.mid(i));
|
||||||
|
|
||||||
switch (c.unicode()) {
|
switch (c.unicode()) {
|
||||||
// Date
|
// Date
|
||||||
|
Loading…
x
Reference in New Issue
Block a user