QLocalSocket (windows) - remove broken setErrorString

We report two types of errors - those found by our code and errors
coming from the OS. setErrorString(), despite its name, does not just
set a string, but extracts a windows error code via GetLastError() and
then calls _q_winError(). This is wrong: some arbitrary error code (or
no error) can be reported when it was actually an error found by
Qt. Worse yet, string operations (allocations etc.) can potentially
clear the real error code. So remove setErrorString(), set errors
explicitly if it's the application code error or use _q_WinError
directly.

Task-number: QTBUG-71744
Change-Id: I67277d84006c4ad365f5636caf850e1f3ba4e1dc
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Timur Pocheptsov 2018-11-13 10:42:14 +01:00
parent 7c93f1cf5d
commit cbac5a1a6e
2 changed files with 6 additions and 11 deletions

View File

@ -131,7 +131,6 @@ public:
#elif defined(Q_OS_WIN)
~QLocalSocketPrivate();
void destroyPipeHandles();
void setErrorString(const QString &function);
void _q_canWrite();
void _q_pipeClosed();
void _q_winError(ulong windowsError, const QString &function);

View File

@ -50,12 +50,6 @@ void QLocalSocketPrivate::init()
q->connect(pipeReader, SIGNAL(winError(ulong,QString)), SLOT(_q_winError(ulong,QString)));
}
void QLocalSocketPrivate::setErrorString(const QString &function)
{
DWORD windowsError = GetLastError();
_q_winError(windowsError, function);
}
void QLocalSocketPrivate::_q_winError(ulong windowsError, const QString &function)
{
Q_Q(QLocalSocket);
@ -127,7 +121,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
{
Q_D(QLocalSocket);
if (state() == ConnectedState || state() == ConnectingState) {
setErrorString(tr("Trying to connect while connection is in progress"));
d->error = OperationError;
d->errorString = tr("Trying to connect while connection is in progress");
emit error(QLocalSocket::OperationError);
return;
}
@ -137,8 +132,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
d->state = ConnectingState;
emit stateChanged(d->state);
if (d->serverName.isEmpty()) {
d->error = QLocalSocket::ServerNotFoundError;
setErrorString(QLocalSocket::tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer")));
d->error = ServerNotFoundError;
d->errorString = tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer"));
d->state = UnconnectedState;
emit error(d->error);
emit stateChanged(d->state);
@ -177,7 +172,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
}
if (localSocket == INVALID_HANDLE_VALUE) {
d->setErrorString(QLatin1String("QLocalSocket::connectToServer"));
const DWORD winError = GetLastError();
d->_q_winError(winError, QLatin1String("QLocalSocket::connectToServer"));
d->fullServerName = QString();
return;
}