From d7f8f7e0783a5e2d6e2324e7bb16001d23f3d7bf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 29 Oct 2013 09:41:08 +0100 Subject: qdbusxml2cpp: Fix warnings about writing to closed devices. Unearthed by fe1cbe9ca78619b54b08e4ec1155d7e6e4e0640a while building QPlatformSupport. Change-Id: Ife56efe111dda6bcf9f11f9c144a4d1dc1651380 Reviewed-by: Laszlo Papp Reviewed-by: Thiago Macieira --- src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp') diff --git a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp index f2b9441ea4..6dd88824b5 100644 --- a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp +++ b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp @@ -509,10 +509,10 @@ static QString stringify(const QString &data) return retval; } -static void openFile(const QString &fileName, QFile &file) +static bool openFile(const QString &fileName, QFile &file) { if (fileName.isEmpty()) - return; + return false; bool isOk = false; if (fileName == QLatin1String("-")) { @@ -525,6 +525,7 @@ static void openFile(const QString &fileName, QFile &file) if (!isOk) fprintf(stderr, "Unable to open '%s': %s\n", qPrintable(fileName), qPrintable(file.errorString())); + return isOk; } static void writeProxy(const QString &filename, const QDBusIntrospection::Interfaces &interfaces) @@ -821,15 +822,17 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf hs.flush(); QFile file; - openFile(headerName, file); - file.write(headerData); + const bool headerOpen = openFile(headerName, file); + if (headerOpen) + file.write(headerData); if (headerName == cppName) { - file.write(cppData); + if (headerOpen) + file.write(cppData); } else { QFile cppFile; - openFile(cppName, cppFile); - cppFile.write(cppData); + if (openFile(cppName, cppFile)) + cppFile.write(cppData); } } @@ -1125,15 +1128,17 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte hs.flush(); QFile file; - openFile(headerName, file); - file.write(headerData); + const bool headerOpen = openFile(headerName, file); + if (headerOpen) + file.write(headerData); if (headerName == cppName) { - file.write(cppData); + if (headerOpen) + file.write(cppData); } else { QFile cppFile; - openFile(cppName, cppFile); - cppFile.write(cppData); + if (openFile(cppName, cppFile)) + cppFile.write(cppData); } } -- cgit v1.2.3