From: Gerhard Sittig Date: Sun, 13 Oct 2019 15:20:16 +0000 (+0200) Subject: input/csv: stricter input data test for multi column mode X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=dbc38383b27b4c754317db4d1c786ba8700c2981;p=libsigrok.git input/csv: stricter input data test for multi column mode The previous implementation assumed that in multi-column mode each cell communicates exactly one bit of input (a logic channel). But only the first character got tested. Tighten the check, to cover the whole input text. This rejects fully invalid input, as well as increases robustness since multi-bit input like "100" was mistaken as a value of 1 before. --- diff --git a/src/input/csv.c b/src/input/csv.c index 6d326490..895c1c6d 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -446,13 +446,13 @@ static int parse_multi_columns(char **columns, struct context *inc) for (i = 0; i < inc->num_channels; i++) { column = columns[i]; - if (column[0] == '1') { + if (strcmp(column, "1") == 0) { inc->sample_buffer[i / 8] |= (1 << (i % 8)); } else if (!strlen(column)) { sr_err("Column %zu in line %zu is empty.", inc->first_channel + i, inc->line_number); return SR_ERR; - } else if (column[0] != '0') { + } else if (strcmp(column, "0") != 0) { sr_err("Invalid value '%s' in column %zu in line %zu.", column, inc->first_channel + i, inc->line_number);