summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2018-03-04 18:11:08 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2018-03-05 15:14:18 +0000
commitea1a95d3567f1264126bf34218a5532ffb5afc51 (patch)
tree557d68184f5d72fa98df1cf6ebd3dba5e8544941 /src
parentaee027f581839caf44de1b176099ef2b22d2fc84 (diff)
downloadqtserialport-ea1a95d3567f1264126bf34218a5532ffb5afc51.tar.gz
Don't poll for POLLIN event if device is open in WriteOnly on Linuxv5.11.0-beta3v5.11.0-beta2
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 <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/serialport/qserialport_unix.cpp3
1 files changed, 2 insertions, 1 deletions
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;
}