aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-03-23 13:44:46 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-03-26 21:33:04 +0100
commit50b9979f89c6bdb761762e8c42176acb6bd7f18c (patch)
tree48d6f83023a95cbf250ff795ccbeb036d0d8d5a6 /tools
parent71d40b09e72c359bc3ea3856140557f16320119a (diff)
QML Tools: add some checks for QFile::open failures
Change-Id: Ic95509efbd7ce33d6e98a52eef3dd319cd328306 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlformat/qmlformat.cpp16
-rw-r--r--tools/qmllint/main.cpp6
-rw-r--r--tools/qmltc/qmltccodewriter.cpp10
3 files changed, 19 insertions, 13 deletions
diff --git a/tools/qmlformat/qmlformat.cpp b/tools/qmlformat/qmlformat.cpp
index 1262bb6391..e26a6412c9 100644
--- a/tools/qmlformat/qmlformat.cpp
+++ b/tools/qmlformat/qmlformat.cpp
@@ -175,11 +175,14 @@ static bool parseFile(const QString &filename, const Options &options)
res = fileItem.writeOut(filename, numberOfBackupFiles, lwOptions, &fw, checks);
} else {
QFile out;
- out.open(stdout, QIODevice::WriteOnly);
- LineWriter lw([&out](QStringView s) { out.write(s.toUtf8()); }, filename, lwOptions);
- OutWriter ow(lw);
- res = fileItem.writeOutForFile(ow, checks);
- ow.flush();
+ if (out.open(stdout, QIODevice::WriteOnly)) {
+ LineWriter lw([&out](QStringView s) { out.write(s.toUtf8()); }, filename, lwOptions);
+ OutWriter ow(lw);
+ res = fileItem.writeOutForFile(ow, checks);
+ ow.flush();
+ } else {
+ res = false;
+ }
}
return res;
}
@@ -259,8 +262,7 @@ Options buildCommandLineOptions(const QCoreApplication &app)
QStringList files;
if (!parser.value("files").isEmpty()) {
QFile file(parser.value("files"));
- file.open(QIODevice::Text | QIODevice::ReadOnly);
- if (file.isOpen()) {
+ if (file.open(QIODevice::Text | QIODevice::ReadOnly)) {
QTextStream in(&file);
while (!in.atEnd()) {
QString file = in.readLine();
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index 0c59e47169..89864c7c38 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -512,8 +512,10 @@ All warnings can be set to three levels:
QTextStream(stdout) << QString::fromUtf8(json);
} else {
QFile file(fileName);
- file.open(QFile::WriteOnly);
- file.write(json);
+ if (file.open(QFile::WriteOnly))
+ file.write(json);
+ else
+ success = false;
}
}
diff --git a/tools/qmltc/qmltccodewriter.cpp b/tools/qmltc/qmltccodewriter.cpp
index d4eb57606c..a8aa0d5f2b 100644
--- a/tools/qmltc/qmltccodewriter.cpp
+++ b/tools/qmltc/qmltccodewriter.cpp
@@ -230,12 +230,14 @@ static void writeToFile(const QString &path, const QByteArray &data)
QFileInfo fi(path);
if (fi.exists() && fi.size() == data.size()) {
QFile oldFile(path);
- oldFile.open(QIODevice::ReadOnly);
- if (oldFile.readAll() == data)
- return;
+ if (oldFile.open(QIODevice::ReadOnly)) {
+ if (oldFile.readAll() == data)
+ return;
+ }
}
QFile file(path);
- file.open(QIODevice::WriteOnly);
+ if (!file.open(QIODevice::WriteOnly))
+ qFatal("Could not open file %s", qPrintable(path));
file.write(data);
}