From 9d118af92db4a522c8b495c273be4780a5265c12 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 22 Mar 2024 17:27:41 +0100 Subject: [PATCH] QTextStream: discard+comment the possibility of file opening failure The QTextStream(FILE*) constructor may fail to open the filehandle through QFile (e.g. if the open mode is incompatible). However QTextStream has no error report mechanism for this and still reports status Ok. This is consistent for instance with the QIODevice* constructor, where even passing a closed device sets the status to Ok. Add a comment and discard the return of open(). Change-Id: I430b96fd26e0ebca15a4d9ee640b09895bdd0b03 Reviewed-by: Thiago Macieira --- src/corelib/serialization/qtextstream.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index c3f1ba7228..e9d650b3e2 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -1002,7 +1002,10 @@ QTextStream::QTextStream(FILE *fileHandle, OpenMode openMode) fileHandle, int(openMode)); #endif QFile *file = new QFile; - file->open(fileHandle, openMode); + // Discarding the return value of open; even if it failed + // (and the file is not open), QTextStream still reports `Ok` + // for closed QIODevices, so there's nothing really to do here. + (void)file->open(fileHandle, openMode); Q_D(QTextStream); d->device = file;