summaryrefslogtreecommitdiff
path: root/serial.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2018-12-26 11:31:19 -0500
committerEric S. Raymond <esr@thyrsus.com>2018-12-26 11:31:19 -0500
commita9f6fa7274855c3bacc13873264bd59e6f3169e3 (patch)
treeb03760d9e67c08ec284676026024e103f0af3a91 /serial.c
parent5144e1c3c1408cb5edf987e26073eab55ef24507 (diff)
downloadgpsd-a9f6fa7274855c3bacc13873264bd59e6f3169e3.tar.gz
Address Savannah bug #53621: Invalid JSON generated for an unreadable device
Diffstat (limited to 'serial.c')
-rw-r--r--serial.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/serial.c b/serial.c
index 7a030cfa..51e5e19f 100644
--- a/serial.c
+++ b/serial.c
@@ -292,6 +292,19 @@ void gpsd_set_speed(struct gps_device_t *session,
else
rate = B230400;
+ /* backward-compatibility hack */
+ switch (parity) {
+ case (char)2:
+ parity = 'E';
+ break;
+ case (char)1:
+ parity = 'O';
+ break;
+ case (char)0:
+ parity = 'N'; /* without this we might emit malformed JSON */
+ break;
+ }
+
if (rate != cfgetispeed(&session->ttyset)
|| parity != session->gpsdata.dev.parity
|| stopbits != session->gpsdata.dev.stopbits) {
@@ -315,12 +328,10 @@ void gpsd_set_speed(struct gps_device_t *session,
session->ttyset.c_cflag |= (stopbits == 2 ? CS7 | CSTOPB : CS8);
switch (parity) {
case 'E':
- case (char)2:
session->ttyset.c_iflag |= INPCK;
session->ttyset.c_cflag |= PARENB;
break;
case 'O':
- case (char)1:
session->ttyset.c_iflag |= INPCK;
session->ttyset.c_cflag |= PARENB | PARODD;
break;