Fix warning about format string not being string literal

Change-Id: I54e80b15b7a492acd4ffdb50a28f00511f72355c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Tor Arne Vestbø
2021-08-03 21:05:54 +02:00
parent 17d716118a
commit 562848f647
2 changed files with 8 additions and 15 deletions

View File

@@ -64,8 +64,7 @@ static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QSet<QSt
{ {
foreach (const QString &filePath, filePaths) { foreach (const QString &filePath, filePaths) {
if (!snapshot.contains(filePath)) { if (!snapshot.contains(filePath)) {
const QString warning = QLatin1String("Missing file in snapshot: ") + filePath; qWarning() << "Missing file in snapshot:" << qPrintable(filePath);
qWarning(qPrintable(warning));
return false; return false;
} }
} }
@@ -247,8 +246,7 @@ bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
{ {
Utils::FileSaver saver(Utils::FilePath::fromString(filePath)); Utils::FileSaver saver(Utils::FilePath::fromString(filePath));
if (!saver.write(contents) || !saver.finalize()) { if (!saver.write(contents) || !saver.finalize()) {
const QString warning = QLatin1String("Failed to write file to disk: ") + filePath; qWarning() << "Failed to write file to disk:" << qPrintable(filePath);
qWarning(qPrintable(warning));
return false; return false;
} }
return true; return true;
@@ -363,7 +361,7 @@ TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
QString errorMessage; QString errorMessage;
if (!copyRecursively(sourceDirPath, path(), &errorMessage)) { if (!copyRecursively(sourceDirPath, path(), &errorMessage)) {
qWarning(qPrintable(errorMessage)); qWarning() << qPrintable(errorMessage);
m_isValid = false; m_isValid = false;
} }
} }
@@ -377,11 +375,8 @@ FileWriterAndRemover::FileWriterAndRemover(const QString &filePath, const QByteA
: m_filePath(filePath) : m_filePath(filePath)
{ {
if (QFileInfo::exists(filePath)) { if (QFileInfo::exists(filePath)) {
const QString warning = QString::fromLatin1( qWarning().nospace() << "Will not overwrite existing file: " << m_filePath << "."
"Will not overwrite existing file: \"%1\"." << " If this file is left over due to a(n) abort/crash, please remove manually.";
" If this file is left over due to a(n) abort/crash, please remove manually.")
.arg(m_filePath);
qWarning(qPrintable(warning));
m_writtenSuccessfully = false; m_writtenSuccessfully = false;
} else { } else {
m_writtenSuccessfully = TestCase::writeFile(filePath, contents); m_writtenSuccessfully = TestCase::writeFile(filePath, contents);
@@ -390,10 +385,8 @@ FileWriterAndRemover::FileWriterAndRemover(const QString &filePath, const QByteA
FileWriterAndRemover::~FileWriterAndRemover() FileWriterAndRemover::~FileWriterAndRemover()
{ {
if (m_writtenSuccessfully && !QFile::remove(m_filePath)) { if (m_writtenSuccessfully && !QFile::remove(m_filePath))
const QString warning = QLatin1String("Failed to remove file from disk: ") + m_filePath; qWarning() << "Failed to remove file from disk:" << qPrintable(m_filePath);
qWarning(qPrintable(warning));
}
} }
VerifyCleanCppModelManager::VerifyCleanCppModelManager() VerifyCleanCppModelManager::VerifyCleanCppModelManager()

View File

@@ -308,7 +308,7 @@ void tst_LanguageServerProtocol::baseMessageParse()
BaseMessage::parse(&buffer, parseError, partial); BaseMessage::parse(&buffer, parseError, partial);
if (!parseError.isEmpty() && !error) // show message if there is an error message we do not expect if (!parseError.isEmpty() && !error) // show message if there is an error message we do not expect
qWarning(parseError.toLatin1()); qWarning() << qPrintable(parseError);
QCOMPARE(!parseError.isEmpty(), error); QCOMPARE(!parseError.isEmpty(), error);
QCOMPARE(partial.content, content); QCOMPARE(partial.content, content);
QCOMPARE(partial.isValid(), valid); QCOMPARE(partial.isValid(), valid);