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 <mr.nuke.me@gmail.com>
This commit is contained in:
Alexandru Gagniuc 2012-12-25 16:21:24 -06:00 committed by Uwe Hermann
parent 0853d5e627
commit 47eda193b2
1 changed files with 3 additions and 3 deletions

View File

@ -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;