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.
This commit is contained in:
Gerhard Sittig 2019-10-13 17:20:16 +02:00
parent 19267272d3
commit dbc38383b2
1 changed files with 2 additions and 2 deletions

View File

@ -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);