From e786b0b0b649223b1c3eb248e700b9b3c3e5a6da Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 14 Nov 2017 12:57:00 +0100 Subject: [PATCH] Use an out-of-range value as undefined The main purpose of the magic value UNDEFINED, is to indicate that a value isn't present in the data. But since the value 0xFF can actually be stored in the data, we can't distinguish between those two cases. This ambiguity can be avoided by using a magic value that lies outside the valid range for 8 and 16 bit fields. Note that an initial gas mix value of 0xFF remains interpreted as UNDEFINED, but this is now made explicit. --- src/hw_ostc_parser.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index f1c656f..a1dc0c3 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -34,7 +34,7 @@ #define MAXCONFIG 7 #define NGASMIXES 15 -#define UNDEFINED 0xFF +#define UNDEFINED 0xFFFFFFFF #define ALL 0 #define FIXED 1 @@ -229,7 +229,9 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) hw_ostc_gasmix_t gasmix[NGASMIXES] = {{0}}; if (version == 0x22) { ngasmixes = 3; - initial = data[31]; + if (data[31] != 0xFF) { + initial = data[31]; + } for (unsigned int i = 0; i < ngasmixes; ++i) { gasmix[i].oxygen = data[25 + 2 * i]; gasmix[i].helium = 0; @@ -250,7 +252,9 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) } } else { ngasmixes = 5; - initial = data[31]; + if (data[31] != 0xFF) { + initial = data[31]; + } for (unsigned int i = 0; i < ngasmixes; ++i) { gasmix[i].oxygen = data[19 + 2 * i + 0]; gasmix[i].helium = data[19 + 2 * i + 1];