Skip to content

Commit

Permalink
input/csv: stricter input data test for multi column mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gsigh committed Dec 21, 2019
1 parent 1926727 commit dbc3838
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/input/csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dbc3838

Please sign in to comment.