From 531e5cb74809d59fb41ff165870ead8de8e8aa23 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 11 Dec 2012 22:14:11 +0100 Subject: [PATCH] Skip the size validation for unused divisors. The recently introduced CNS support caused a regression for older firmware versions. If a firmware doesn't support a certain sample yet, the corresponding sample divisor and size are both equal to zero (the default value for unused bytes). However, because the size was always checked, regardless of whether the sample is actually present or not, this zero size caused the parsing to fail. To fix the regression, the size is now only checked when the divisor indicates the sample is actually present. --- src/hw_ostc_parser.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 87d8949..361a7c3 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -296,18 +296,20 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call for (unsigned int i = 0; i < NINFO; ++i) { info[i].divisor = (data[37 + i] & 0x0F); info[i].size = (data[37 + i] & 0xF0) >> 4; - switch (i) { - case 0: // Temperature - case 1: // Deco / NDL - if (info[i].size != 2) - return DC_STATUS_DATAFORMAT; - break; - case 5: // CNS - if (info[i].size != 1) - return DC_STATUS_DATAFORMAT; - break; - default: // Not yet used. - break; + if (info[i].divisor) { + switch (i) { + case 0: // Temperature + case 1: // Deco / NDL + if (info[i].size != 2) + return DC_STATUS_DATAFORMAT; + break; + case 5: // CNS + if (info[i].size != 1) + return DC_STATUS_DATAFORMAT; + break; + default: // Not yet used. + break; + } } }