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 <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
fc04905281
commit
a847f5cd85
@ -1923,12 +1923,14 @@ void qErrnoWarning(const char *msg, ...)
|
|||||||
{
|
{
|
||||||
// qt_error_string() will allocate anyway, so we don't have
|
// qt_error_string() will allocate anyway, so we don't have
|
||||||
// to be careful here (like we do in plain qWarning())
|
// 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_list ap;
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
QString buf = QString::vasprintf(msg, ap);
|
QString buf = QString::vasprintf(msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')');
|
buf += QLatin1String(" (") + error_string + QLatin1Char(')');
|
||||||
QMessageLogContext context;
|
QMessageLogContext context;
|
||||||
qt_message_output(QtCriticalMsg, context, buf);
|
qt_message_output(QtCriticalMsg, context, buf);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user