From 3502ad39a64ad6ab4d2d7c4aa0c03714f138f93a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 1 Dec 2012 12:45:16 +0100 Subject: [PATCH] Check the salinity byte for out of range values. Apparently some older firmware versions don't support the salinity setting. Because unused bytes are initialized with zero, the salinity value will be reported as being zero. To fix this unexpected value, the salinity factor is first checked for valid values. If the value is out of range, a DC_STATUS_UNSUPPORTED error is returned to indicate the absence of the value. --- src/hw_ostc_parser.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index c209743..ffeba04 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -212,6 +212,7 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_salinity_t *water = (dc_salinity_t *) value; + unsigned int salinity = data[43]; if (value) { switch (type) { @@ -236,11 +237,14 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; break; case DC_FIELD_SALINITY: - if (data[43] == 100) + if (salinity < 100 || salinity > 104) + return DC_STATUS_UNSUPPORTED; + + if (salinity == 100) water->type = DC_WATER_FRESH; else water->type = DC_WATER_SALT; - water->density = data[43] * 10.0; + water->density = salinity * 10.0; break; case DC_FIELD_ATMOSPHERIC: *((double *) value) = array_uint16_le (data + 15) / 1000.0;