From ea1a95d3567f1264126bf34218a5532ffb5afc51 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sun, 4 Mar 2018 18:11:08 +0300 Subject: Don't poll for POLLIN event if device is open in WriteOnly on Linux Following code snippet: QSerialPort serial("/dev/ttyUSB0"); serial.open(QIODevice::WriteOnly); serial.write("ABCDEF"); serial.waitForBytesWritten(-1); causes an application crash if some of data will be received by the serial port. Reason is that qt_poll_msecs() triggered with POLLIN event, even if the device is opened with O_WRONLY flag. In this case the readNotification() handler is called, which trying to reserve some space from the uninitialized read QRingBuffer, that causes an assertion. Solution is to don't use the POLLIN event if device is open with O_WRONLY flag. Change-Id: I205be31608359f52b5ef286a33dd266ed11a2649 Reviewed-by: Thiago Macieira Reviewed-by: Oswald Buddenhagen --- src/serialport/qserialport_unix.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index a13a289..dd0339f 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -526,7 +526,8 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs) for (;;) { bool readyToRead = false; bool readyToWrite = false; - if (!waitForReadOrWrite(&readyToRead, &readyToWrite, true, !writeBuffer.isEmpty(), + const bool checkRead = q_func()->isReadable(); + if (!waitForReadOrWrite(&readyToRead, &readyToWrite, checkRead, !writeBuffer.isEmpty(), qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) { return false; } -- cgit v1.2.1