Misc: Fix qsizetype-related narrowing coversions

Task-number: QTBUG-102461
Change-Id: I96757abc50fc45756bc1271a970f819a48021663
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-03-08 13:06:21 +02:00
parent dda60cf0d1
commit 8a1eb24de8
10 changed files with 26 additions and 27 deletions

View File

@ -542,8 +542,8 @@ QString QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath p, UsageMode usageMo
ret = v.toString(); ret = v.toString();
} }
int startIndex = 0; qsizetype startIndex = 0;
forever { while (true) {
startIndex = ret.indexOf(u'$', startIndex); startIndex = ret.indexOf(u'$', startIndex);
if (startIndex < 0) if (startIndex < 0)
break; break;
@ -553,7 +553,7 @@ QString QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath p, UsageMode usageMo
startIndex++; startIndex++;
continue; continue;
} }
int endIndex = ret.indexOf(u')', startIndex + 2); qsizetype endIndex = ret.indexOf(u')', startIndex + 2);
if (endIndex < 0) if (endIndex < 0)
break; break;
auto envVarName = QStringView{ret}.mid(startIndex + 2, endIndex - startIndex - 2); auto envVarName = QStringView{ret}.mid(startIndex + 2, endIndex - startIndex - 2);

View File

@ -352,8 +352,7 @@ static QByteArray getEtcFileFirstLine(const char *fileName)
return QByteArray(); return QByteArray();
const char *ptr = buffer.constData(); const char *ptr = buffer.constData();
int eol = buffer.indexOf("\n"); return QByteArray(ptr, buffer.indexOf("\n")).trimmed();
return QByteArray(ptr, eol).trimmed();
} }
static bool readEtcRedHatRelease(QUnixOSVersion &v) static bool readEtcRedHatRelease(QUnixOSVersion &v)
@ -368,9 +367,9 @@ static bool readEtcRedHatRelease(QUnixOSVersion &v)
v.prettyName = QString::fromLatin1(line); v.prettyName = QString::fromLatin1(line);
const char keyword[] = "release "; const char keyword[] = "release ";
int releaseIndex = line.indexOf(keyword); const qsizetype releaseIndex = line.indexOf(keyword);
v.productType = QString::fromLatin1(line.mid(0, releaseIndex)).remove(u' '); v.productType = QString::fromLatin1(line.mid(0, releaseIndex)).remove(u' ');
int spaceIndex = line.indexOf(' ', releaseIndex + strlen(keyword)); const qsizetype spaceIndex = line.indexOf(' ', releaseIndex + strlen(keyword));
v.productVersion = QString::fromLatin1(line.mid(releaseIndex + strlen(keyword), v.productVersion = QString::fromLatin1(line.mid(releaseIndex + strlen(keyword),
spaceIndex > -1 ? spaceIndex - releaseIndex - int(strlen(keyword)) : -1)); spaceIndex > -1 ? spaceIndex - releaseIndex - int(strlen(keyword)) : -1));
return true; return true;

View File

@ -1104,7 +1104,7 @@ static bool createDirectoryWithParents(const QByteArray &nativeName, mode_t mode
return false; return false;
// mkdir failed because the parent dir doesn't exist, so try to create it // mkdir failed because the parent dir doesn't exist, so try to create it
int slash = nativeName.lastIndexOf('/'); qsizetype slash = nativeName.lastIndexOf('/');
if (slash < 1) if (slash < 1)
return false; return false;
@ -1147,7 +1147,7 @@ bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool remo
if (removeEmptyParents) { if (removeEmptyParents) {
QString dirName = QDir::cleanPath(entry.filePath()); QString dirName = QDir::cleanPath(entry.filePath());
for (int oldslash = 0, slash=dirName.size(); slash > 0; oldslash = slash) { for (qsizetype oldslash = 0, slash=dirName.size(); slash > 0; oldslash = slash) {
const QByteArray chunk = QFile::encodeName(dirName.left(slash)); const QByteArray chunk = QFile::encodeName(dirName.left(slash));
QT_STATBUF st; QT_STATBUF st;
if (QT_STAT(chunk.constData(), &st) != -1) { if (QT_STAT(chunk.constData(), &st) != -1) {

View File

@ -67,7 +67,7 @@ int QLoggingRule::pass(QLatin1StringView cat, QtMsgType msgType) const
return 0; return 0;
} }
const int idx = cat.indexOf(category); const qsizetype idx = cat.indexOf(category);
if (idx >= 0) { if (idx >= 0) {
if (flags == MidFilter) { if (flags == MidFilter) {
// matches somewhere // matches somewhere
@ -194,7 +194,7 @@ void QLoggingSettingsParser::parseNextLine(QStringView line)
} }
if (m_inRulesSection) { if (m_inRulesSection) {
int equalPos = line.indexOf(u'='); const qsizetype equalPos = line.indexOf(u'=');
if (equalPos != -1) { if (equalPos != -1) {
if (line.lastIndexOf(u'=') == equalPos) { if (line.lastIndexOf(u'=') == equalPos) {
const auto key = line.left(equalPos).trimmed(); const auto key = line.left(equalPos).trimmed();

View File

@ -72,7 +72,7 @@ QProcessEnvironment QProcessEnvironmentPrivate::fromList(const QStringList &list
QStringList::ConstIterator it = list.constBegin(), QStringList::ConstIterator it = list.constBegin(),
end = list.constEnd(); end = list.constEnd();
for ( ; it != end; ++it) { for ( ; it != end; ++it) {
int pos = it->indexOf(u'=', 1); const qsizetype pos = it->indexOf(u'=', 1);
if (pos < 1) if (pos < 1)
continue; continue;

View File

@ -82,7 +82,7 @@ public:
inline QStringView next() inline QStringView next()
{ {
int start = m_pos; const qsizetype start = m_pos;
while (m_pos < m_len && m_data[m_pos] != m_splitChar) while (m_pos < m_len && m_data[m_pos] != m_splitChar)
++m_pos; ++m_pos;
return QStringView(m_data + start, m_pos - start); return QStringView(m_data + start, m_pos - start);
@ -1478,14 +1478,14 @@ QString QResourceFileEngine::fileName(FileName file) const
{ {
Q_D(const QResourceFileEngine); Q_D(const QResourceFileEngine);
if (file == BaseName) { if (file == BaseName) {
int slash = d->resource.fileName().lastIndexOf(u'/'); const qsizetype slash = d->resource.fileName().lastIndexOf(u'/');
if (slash == -1) if (slash == -1)
return d->resource.fileName(); return d->resource.fileName();
return d->resource.fileName().mid(slash + 1); return d->resource.fileName().mid(slash + 1);
} else if (file == PathName || file == AbsolutePathName) { } else if (file == PathName || file == AbsolutePathName) {
const QString path = (file == AbsolutePathName) ? d->resource.absoluteFilePath() const QString path = (file == AbsolutePathName) ? d->resource.absoluteFilePath()
: d->resource.fileName(); : d->resource.fileName();
const int slash = path.lastIndexOf(u'/'); const qsizetype slash = path.lastIndexOf(u'/');
if (slash == -1) if (slash == -1)
return ":"_L1; return ":"_L1;
else if (slash <= 1) else if (slash <= 1)
@ -1495,7 +1495,7 @@ QString QResourceFileEngine::fileName(FileName file) const
} else if (file == CanonicalName || file == CanonicalPathName) { } else if (file == CanonicalName || file == CanonicalPathName) {
const QString absoluteFilePath = d->resource.absoluteFilePath(); const QString absoluteFilePath = d->resource.absoluteFilePath();
if (file == CanonicalPathName) { if (file == CanonicalPathName) {
const int slash = absoluteFilePath.lastIndexOf(u'/'); const qsizetype slash = absoluteFilePath.lastIndexOf(u'/');
if (slash != -1) if (slash != -1)
return absoluteFilePath.left(slash); return absoluteFilePath.left(slash);
} }

View File

@ -558,7 +558,7 @@ bool QSettingsPrivate::iniUnescapedKey(QByteArrayView key, QString &result)
} }
int numDigits = 2; int numDigits = 2;
int firstDigitPos = i + 1; qsizetype firstDigitPos = i + 1;
ch = decoded.at(i + 1).unicode(); ch = decoded.at(i + 1).unicode();
if (ch == 'U') { if (ch == 'U') {

View File

@ -230,7 +230,7 @@ QString QMimeType::comment() const
const QString comm = d->localeComments.value(lang); const QString comm = d->localeComments.value(lang);
if (!comm.isEmpty()) if (!comm.isEmpty())
return comm; return comm;
const int pos = lang.indexOf(u'_'); const qsizetype pos = lang.indexOf(u'_');
if (pos != -1) { if (pos != -1) {
// "pt_BR" not found? try just "pt" // "pt_BR" not found? try just "pt"
const QString shortLang = lang.left(pos); const QString shortLang = lang.left(pos);
@ -269,7 +269,7 @@ QString QMimeType::genericIconName() const
// (i.e. "video-x-generic" in the previous example). // (i.e. "video-x-generic" in the previous example).
const QString group = name(); const QString group = name();
QStringView groupRef(group); QStringView groupRef(group);
const int slashindex = groupRef.indexOf(u'/'); const qsizetype slashindex = groupRef.indexOf(u'/');
if (slashindex != -1) if (slashindex != -1)
groupRef = groupRef.left(slashindex); groupRef = groupRef.left(slashindex);
return groupRef + "-x-generic"_L1; return groupRef + "-x-generic"_L1;
@ -279,7 +279,7 @@ QString QMimeType::genericIconName() const
static QString make_default_icon_name_from_mimetype_name(QString iconName) static QString make_default_icon_name_from_mimetype_name(QString iconName)
{ {
const int slashindex = iconName.indexOf(u'/'); const qsizetype slashindex = iconName.indexOf(u'/');
if (slashindex != -1) if (slashindex != -1)
iconName[slashindex] = u'-'; iconName[slashindex] = u'-';
return iconName; return iconName;

View File

@ -1252,7 +1252,7 @@ Q_NEVER_INLINE static int ucstricmp8(const char *utf8, const char *utf8end, cons
char32_t uc1 = 0; char32_t uc1 = 0;
char32_t *output = &uc1; char32_t *output = &uc1;
uchar b = *src1++; uchar b = *src1++;
int res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, output, src1, end1); const qsizetype res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, output, src1, end1);
if (res < 0) { if (res < 0) {
// decoding error // decoding error
uc1 = QChar::ReplacementCharacter; uc1 = QChar::ReplacementCharacter;

View File

@ -651,7 +651,7 @@ char16_t *QUtf8::convertToUnicode(char16_t *dst, QByteArrayView in) noexcept
do { do {
uchar b = *src++; uchar b = *src++;
int res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, dst, src, end); const qsizetype res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, dst, src, end);
if (res < 0) { if (res < 0) {
// decoding error // decoding error
*dst++ = QChar::ReplacementCharacter; *dst++ = QChar::ReplacementCharacter;
@ -694,7 +694,7 @@ char16_t *QUtf8::convertToUnicode(char16_t *dst, QByteArrayView in, QStringConve
if (state->flags & QStringConverter::Flag::ConvertInvalidToNull) if (state->flags & QStringConverter::Flag::ConvertInvalidToNull)
replacement = QChar::Null; replacement = QChar::Null;
int res; qsizetype res;
uchar ch = 0; uchar ch = 0;
const uchar *src = reinterpret_cast<const uchar *>(in.data()); const uchar *src = reinterpret_cast<const uchar *>(in.data());
@ -810,7 +810,7 @@ QUtf8::ValidUtf8Result QUtf8::isValidUtf8(QByteArrayView in)
isValidAscii = false; isValidAscii = false;
QUtf8NoOutputTraits::NoOutput output; QUtf8NoOutputTraits::NoOutput output;
int res = QUtf8Functions::fromUtf8<QUtf8NoOutputTraits>(b, output, src, end); const qsizetype res = QUtf8Functions::fromUtf8<QUtf8NoOutputTraits>(b, output, src, end);
if (res < 0) { if (res < 0) {
// decoding error // decoding error
return { false, false }; return { false, false };
@ -837,7 +837,7 @@ int QUtf8::compareUtf8(QByteArrayView utf8, QStringView utf16, Qt::CaseSensitivi
if (uc1 >= 0x80) { if (uc1 >= 0x80) {
char32_t *output = &uc1; char32_t *output = &uc1;
int res = QUtf8Functions::fromUtf8<QUtf8BaseTraitsNoAscii>(uc1, output, src1, end1); qsizetype res = QUtf8Functions::fromUtf8<QUtf8BaseTraitsNoAscii>(uc1, output, src1, end1);
if (res < 0) { if (res < 0) {
// decoding error // decoding error
uc1 = QChar::ReplacementCharacter; uc1 = QChar::ReplacementCharacter;
@ -872,7 +872,7 @@ int QUtf8::compareUtf8(QByteArrayView utf8, QLatin1StringView s, Qt::CaseSensiti
while (src1 < end1 && src2 < end2) { while (src1 < end1 && src2 < end2) {
uchar b = *src1++; uchar b = *src1++;
char32_t *output = &uc1; char32_t *output = &uc1;
int res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, output, src1, end1); const qsizetype res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, output, src1, end1);
if (res < 0) { if (res < 0) {
// decoding error // decoding error
uc1 = QChar::ReplacementCharacter; uc1 = QChar::ReplacementCharacter;
@ -912,7 +912,7 @@ int QUtf8::compareUtf8(QByteArrayView lhs, QByteArrayView rhs, Qt::CaseSensitivi
while (src1 < end1 && src2 < end2) { while (src1 < end1 && src2 < end2) {
uchar b = *src1++; uchar b = *src1++;
char32_t *output = &uc1; char32_t *output = &uc1;
int res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, output, src1, end1); qsizetype res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, output, src1, end1);
if (res < 0) { if (res < 0) {
// decoding error // decoding error
uc1 = QChar::ReplacementCharacter; uc1 = QChar::ReplacementCharacter;