Skip to content
Snippets Groups Projects
Commit c13bcd2d authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Add sanity check of values returned from serial2002_read

parent 7486a175
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,10 @@ static struct moberg_status analog_in_read(
}
result = serial2002_read(device->port.fd, device->port.timeout, &data);
if (OK(result)) {
if ((data.kind != is_channel) || (data.index != map.index)) {
result = MOBERG_ERRNO(ECHRNG);
goto return_result;
}
*value = (data.value * map.delta + map.min);
}
return_result:
......@@ -173,6 +177,10 @@ static struct moberg_status digital_in_read(
}
result = serial2002_read(device->port.fd, device->port.timeout, &data);
if (OK(result)) {
if ((data.kind != is_digital) || (data.index != map.index)) {
result = MOBERG_ERRNO(ECHRNG);
goto return_result;
}
*value = data.value != 0;
}
return_result:
......@@ -216,6 +224,10 @@ static struct moberg_status encoder_in_read(
}
result = serial2002_read(device->port.fd, device->port.timeout, &data);
if (OK(result)) {
if ((data.kind != is_channel) || (data.index != map.index)) {
result = MOBERG_ERRNO(ECHRNG);
goto return_result;
}
*value = (data.value);
}
return_result:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment