From 571df62ce5a70c98df546ee062eb90d474ffabad Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 13 Jul 2023 13:49:00 -0700 Subject: [PATCH] garmin_parser: be a little less abrupt about parsing errors Instead of returning an error on unrecognized input when parsing, just skip to the end of the buffer. This makes at least partially parsed data available, which can help figure out what ended up happening. This was part of my "Suunto also does FIT files now, and does them very differently from Garmin" series. I think I parse the Suunto files right now, but next time this happens, I'd rather get partial data than no data at all. Signed-off-by: Linus Torvalds --- src/garmin_parser.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/garmin_parser.c b/src/garmin_parser.c index 782a01e..a641b34 100644 --- a/src/garmin_parser.c +++ b/src/garmin_parser.c @@ -1241,20 +1241,17 @@ static int traverse_regular(struct garmin_parser_t *garmin, if (!len) { ERROR(garmin->base.context, "field with zero length\n"); - return -1; + return total_len + size; } if (size < len) { ERROR(garmin->base.context, "Data traversal size bigger than remaining data (%d vs %d)\n", len, size); - return -1; + return total_len + size; } if (base_type > 16) { ERROR(garmin->base.context, "Unknown base type %d\n", base_type); - data += size; - len -= size; - total_len += size; - continue; + return total_len + size; } base_size = base_type_info[base_type].type_size; if (len % base_size) {