From a847f5cd8562d3d42fb4cbdb42367466119f8d5f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 5 Aug 2019 08:51:10 -0700 Subject: [PATCH] Fix qErrnoWarning() printing no error in some conditions Because it allocates memory, it may call system functions that set errno or Win32's GetLastError(). [ChangeLog][QtCore] Fixed a bug that made qErrnoWarning() say there was no error when generating the error message. Fixes: QTBUG-77322 Change-Id: Ife213d861bb14c1787e1fffd15b811a4f83cf3e7 Reviewed-by: Friedemann Kleint --- src/corelib/global/qlogging.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 1a74757032..bf9c2ed2be 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1923,12 +1923,14 @@ void qErrnoWarning(const char *msg, ...) { // qt_error_string() will allocate anyway, so we don't have // to be careful here (like we do in plain qWarning()) + QString error_string = qt_error_string(-1); // before vasprintf changes errno/GetLastError() + va_list ap; va_start(ap, msg); QString buf = QString::vasprintf(msg, ap); va_end(ap); - buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')'); + buf += QLatin1String(" (") + error_string + QLatin1Char(')'); QMessageLogContext context; qt_message_output(QtCriticalMsg, context, buf); }