From: Alexandru Gagniuc Date: Tue, 25 Dec 2012 22:21:24 +0000 (-0600) Subject: rs9lcd: Fix segfault with unusual modes. X-Git-Tag: dsupstream~409 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=47eda193b2ce105ce50ddd284c99d813dacc49a7;p=libsigrok.git rs9lcd: Fix segfault with unusual modes. Some unusual modes required re-parsing the value. Instead of assigning the re-parsed value to *floatval, it was reassigned directly to *analog->data; however, analog->data is not initialized at this point, causing a segfault. This situation was created when moving the radioshack-dmm code to serial-dmm, with the segfault not being observed at that time. Do not write directly to analog->data, but instead use the intermediate variable rawval. Signed-off-by: Alexandru Gagniuc --- diff --git a/hardware/common/dmm/rs9lcd.c b/hardware/common/dmm/rs9lcd.c index d184aca7..25e33070 100644 --- a/hardware/common/dmm/rs9lcd.c +++ b/hardware/common/dmm/rs9lcd.c @@ -369,7 +369,7 @@ SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval, case MODE_CONT: analog->mq = SR_MQ_CONTINUITY; analog->unit = SR_UNIT_BOOLEAN; - *analog->data = is_shortcirc(rs_packet); + rawval = is_shortcirc(rs_packet); break; case MODE_DIODE: analog->mq = SR_MQ_VOLTAGE; @@ -394,7 +394,7 @@ SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval, } else { /* We have either HI or LOW. */ analog->unit = SR_UNIT_BOOLEAN; - *analog->data = is_logic_high(rs_packet); + rawval = is_logic_high(rs_packet); } break; case MODE_HFE: @@ -415,7 +415,7 @@ SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval, case MODE_TEMP: analog->mq = SR_MQ_TEMPERATURE; /* We need to reparse. */ - *analog->data = lcd_to_double(rs_packet, READ_TEMP); + rawval = lcd_to_double(rs_packet, READ_TEMP); analog->unit = is_celsius(rs_packet) ? SR_UNIT_CELSIUS : SR_UNIT_FAHRENHEIT; break;