Initialize the termios structure.

The previous commit exposed another issue. The termios structure may
contain padding bytes. Because the content of those padding bytes is
unspecified, they may contain some random data, which causes the memcmp
to fail.

Explicitly initializing the termios structure with memset, will also set
the padding bytes to zero.
This commit is contained in:
Jef Driesen 2014-05-14 09:52:34 +02:00
parent 3001dda198
commit 5f1a18653d

View File

@ -233,6 +233,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// Retrieve the current settings.
struct termios tty;
memset (&tty, 0, sizeof (tty));
if (tcgetattr (device->fd, &tty) != 0) {
SYSERROR (device->context, errno);
return -1;
@ -422,6 +423,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// tcgetattr() to check that all changes have been performed successfully.
struct termios active;
memset (&active, 0, sizeof (active));
if (tcgetattr (device->fd, &active) != 0) {
SYSERROR (device->context, errno);
return -1;