diff options
| author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2024-03-23 13:44:46 +0100 |
|---|---|---|
| committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2024-03-26 21:33:04 +0100 |
| commit | 50b9979f89c6bdb761762e8c42176acb6bd7f18c (patch) | |
| tree | 48d6f83023a95cbf250ff795ccbeb036d0d8d5a6 /tools/qmlformat/qmlformat.cpp | |
| parent | 71d40b09e72c359bc3ea3856140557f16320119a (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/qmlformat/qmlformat.cpp')
| -rw-r--r-- | tools/qmlformat/qmlformat.cpp | 16 |
1 files changed, 9 insertions, 7 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(); |
