From b8fa58abf012c00d1a0a51799ac77333c715527d Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 20 Aug 2019 21:38:02 +0300 Subject: [PATCH] onewire_parser: Fix "85" degree handling case The current method of comparing the beginning of the raw string to "85" will discard all measurements, even valid ones that are different than strictly "85". This includes values such as 85.5, which can be 100% correct. This also fixes a small memory leak that took place when we actually got "85" from the sensor. If that happens, it is a failure, but the *_read() function still had allocated the string for us. So it must be freed. Signed-off-by: Timo Kokkonen --- onewire_parser.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/onewire_parser.c b/onewire_parser.c index 7d1e8a6..e129e5c 100644 --- a/onewire_parser.c +++ b/onewire_parser.c @@ -50,6 +50,10 @@ static int might_be_glitch(double data, const struct owparser_state *s) { double max_delta, delta; + /* The known bad data value from the sensor */ + if (data == 85) + return 1; + max_delta = max_glitch_delta(s); /* Probably no enough data yet, so no glitch detection */ @@ -255,7 +259,7 @@ undefined: parse_opts(parser_data[i], ow_path, sizeof(ow_path), &offset); while (1) { - int fail, j; + int j; char *tmp2; tmp = NULL; @@ -272,15 +276,9 @@ undefined: for (j = 0; j < ret && *tmp2 == ' '; j++) tmp2++; - if (ret > 0) - fail = !strncmp(tmp2, "85", 2); - else - fail = 1; - - if (ret <= 0 || fail) + if (ret <= 0) goto retry; - /* * Older versions of OWNET_read did not NULL * terminate data. -- 2.45.0