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.
This commit is contained in:
Jef Driesen 2017-11-14 12:57:00 +01:00
parent d0d4c7b994
commit e786b0b0b6

View File

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