From: Antonio Ospite Date: Wed, 4 Nov 2015 12:54:28 +0000 (+0100) Subject: Fix parsing the eeprom when there are users with no records X-Git-Url: https://git.ao2.it/visomat-utils.git/commitdiff_plain/8d67f9a624e9097a7c99513dd0e73daf3b59ae8d?ds=inline Fix parsing the eeprom when there are users with no records When the number of records for a given user is 0, there is a dummy byte at the end of the user memory block which has to be consumed as well, otherwise the while loop never ends. The bug was found out by Cornelis Broeders --- diff --git a/README b/README index 10b889e..f8a07e9 100644 --- a/README +++ b/README @@ -68,3 +68,19 @@ The structure can be better visualized when split in fields: 440601 1319 0 114 063 066 100101 1400 0 114 070 071 130312 1145 0 121 080 072 + +When the number of records is 0, there is a dummy byte at the end of the user +memory block, e.g.: + + M1001M20115110321300134097083 + +The structure is: + + M + 1 + 00 + 1 # dummy byte, present only when the previous field is 00 + M + 2 + 01 + 151103 2130 0 134 097 083 diff --git a/src/visomat-data-downloader.c b/src/visomat-data-downloader.c index c2b8590..97da8e8 100644 --- a/src/visomat-data-downloader.c +++ b/src/visomat-data-downloader.c @@ -156,6 +156,13 @@ static int decode_eeprom(unsigned char *buffer, /* user_id and num_records take 3 bytes */ i += 3; + /* + * when there are no records, there is a dummy byte + * which has to be consumed + */ + if (num_records == 0) + i += 1; + for (j = 0; j < num_records; j++) { ret = extract_datetime(buffer + i, &d); if (ret < 0)