Skip to content
Myr

column: fix off-by-one when splitting input into columns

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The call to c32chr() (to find the *next* column) did a plus one on the last columns start. Presumably to skip the delimiter. But the column start offsets have already accounted for this, meaning c32chr() failed if the previous column was empty. Closes #658

authored by Daniel Eklöf · committed by Daniel Eklöf · parent c09c9a6 · Browse files · 2 files+10 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−4 removed

  • other:+10 added−4 removed

2 files+10 added−4 removed

modified:CHANGELOG.md+7 added
35 unmodified lines
36### Changed37### Deprecated38### Removed39### Fixed4041* `--with-nth` and `--accept-nth` crashing if a column is empty42 (e.g. `\tsecond column`, or `first\t\tthird`) ([#658][658])4344[658]: https://codeberg.org/dnkl/fuzzel/issues/658454647### Security48### Contributors4950
1047 unmodified lines
modified:column.c+3 added-4 removed
28 unmodified lines
29 size_t col_lens[col_count];3031 col_starts[0] = string;32 for (size_t i = 1; i < col_count; i++) {33 const char32_t *next = c32chr(col_starts[i - 1] + 1, delim);33 const char32_t *next = c32chr(col_starts[i - 1], delim);3435 xassert(next != NULL);36 col_starts[i] = next + 1;37 col_lens[i - 1] = next - col_starts[i - 1];
1 unmodified line
3940 col_lens[col_count - 1] = string_end - col_starts[col_count - 1];4142 for (size_t i = 0; i < col_count; i++) {43 LOG_DBG("col #%zu: \"%.*ls\"", i,44 (int)col_lens[i],45 (const wchar_t *)col_starts[i]);43 LOG_DBG("col #%zu: \"%.*ls\" (%zu chars)", i,44 (int)col_lens[i], (const wchar_t *)col_starts[i], col_lens[i]);45 }4647 /* TODO: allocate dynamically */48 char32_t *result = NULL;
137 unmodified lines