summaryrefslogtreecommitdiff
path: root/gpsd_json.c
diff options
context:
space:
mode:
authorJon Schlueter <jschlueter@redhat.com>2015-10-06 03:13:49 -0400
committerJon Schlueter <jschlueter@redhat.com>2015-10-06 03:17:40 -0400
commit5c20d030c70578d6d212b00cc972e2b19d5abf9c (patch)
tree032f3af5412570069bcfd01fe2b9ea65988bc68f /gpsd_json.c
parent7a5aa615ba26763169757ebf53ea8611ed9856a4 (diff)
downloadgpsd-5c20d030c70578d6d212b00cc972e2b19d5abf9c.tar.gz
Fix json_aivdm_dump for bad temp scaling
- Type 8, DAC = 1 FID = 11: airtemp, dewpoint and watertemp calculations go wrong due to unsigned ints. Identified by: Stefan Roels <sroels-gpsd-dev@42solutions.nl> unsigned/signed subtraction was causing math to go wonky. new sample data added to sample.aivdm which exibits the conversion errors Also identified watertemp that was failing from same data Regenerated the corresponding check files from current code
Diffstat (limited to 'gpsd_json.c')
-rw-r--r--gpsd_json.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/gpsd_json.c b/gpsd_json.c
index 9ccad3dd..530ee3dd 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -2167,8 +2167,8 @@ void json_aivdm_dump(const struct ais_t *ais,
str_appendf(buf, buflen,
"\"airtemp\":%.1f,\"dewpoint\":%.1f,"
"\"pressure\":%u,\"pressuretend\":\"%s\",",
- (ais->type8.dac1fid11.airtemp - DAC1FID11_AIRTEMP_OFFSET) / DAC1FID11_AIRTEMP_DIV,
- (ais->type8.dac1fid11.dewpoint - DAC1FID11_DEWPOINT_OFFSET) / DAC1FID11_DEWPOINT_DIV,
+ ((signed int)ais->type8.dac1fid11.airtemp - DAC1FID11_AIRTEMP_OFFSET) / DAC1FID11_AIRTEMP_DIV,
+ ((signed int)ais->type8.dac1fid11.dewpoint - DAC1FID11_DEWPOINT_OFFSET) / DAC1FID11_DEWPOINT_DIV,
ais->type8.dac1fid11.pressure - DAC1FID11_PRESSURE_OFFSET,
trends[ais->type8.dac1fid11.pressuretend]);
else
@@ -2195,7 +2195,7 @@ void json_aivdm_dump(const struct ais_t *ais,
else
str_appendf(buf, buflen,
"\"waterlevel\":%.1f,",
- (ais->type8.dac1fid11.waterlevel - DAC1FID11_WATERLEVEL_OFFSET) / DAC1FID11_WATERLEVEL_DIV);
+ ((signed int)ais->type8.dac1fid11.waterlevel - DAC1FID11_WATERLEVEL_OFFSET) / DAC1FID11_WATERLEVEL_DIV);
if (scaled) {
str_appendf(buf, buflen,
@@ -2224,7 +2224,7 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type8.dac1fid11.swellperiod,
ais->type8.dac1fid11.swelldir,
ais->type8.dac1fid11.seastate,
- (ais->type8.dac1fid11.watertemp - DAC1FID11_WATERTEMP_OFFSET) / DAC1FID11_WATERTEMP_DIV,
+ ((signed int)ais->type8.dac1fid11.watertemp - DAC1FID11_WATERTEMP_OFFSET) / DAC1FID11_WATERTEMP_DIV,
ais->type8.dac1fid11.preciptype,
preciptypes[ais->type8.dac1fid11.preciptype],
ais->type8.dac1fid11.salinity / DAC1FID11_SALINITY_DIV,
@@ -2483,7 +2483,7 @@ void json_aivdm_dump(const struct ais_t *ais,
else
str_appendf(buf, buflen,
"\"waterlevel\":%.1f,",
- (ais->type8.dac1fid31.waterlevel - DAC1FID31_WATERLEVEL_OFFSET) / DAC1FID31_WATERLEVEL_DIV);
+ ((unsigned int)ais->type8.dac1fid31.waterlevel - DAC1FID31_WATERLEVEL_OFFSET) / DAC1FID31_WATERLEVEL_DIV);
if (scaled) {
str_appendf(buf, buflen,