diff options
| author | Paul Eggert <eggert@cs.ucla.edu> | 2023-10-30 10:47:34 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-10-30 10:49:44 -0700 |
| commit | 56e9acb2927874770363462cc6f5d2ee7d2b4c6d (patch) | |
| tree | f6718eac2117a3d3ed400f68cc0dc941c85a7e3a | |
| parent | maint: pacify ‘make syntax-check’ (diff) | |
| download | coreutils-56e9acb2927874770363462cc6f5d2ee7d2b4c6d.tar.gz coreutils-56e9acb2927874770363462cc6f5d2ee7d2b4c6d.zip | |
join: fix recently introduced NUL bug
* src/join.c (xfields): Simplify and fix bug with fields
that start with a NUL byte when -t is not used.
* tests/misc/join-utf8.sh: Also test when -t is not used,
and when a field starts with NUL.
| -rw-r--r-- | src/join.c | 20 | ||||
| -rwxr-xr-x | tests/misc/join-utf8.sh | 10 |
2 files changed, 14 insertions, 16 deletions
diff --git a/src/join.c b/src/join.c index b3ad27465..a89b5de28 100644 --- a/src/join.c +++ b/src/join.c @@ -296,23 +296,17 @@ xfields (struct line *line) return; if (!tab.len) - { - while (ptr < lim) - { - ptr = skip_buf_matching (ptr, lim, newline_or_blank, true); - if (!*ptr) - break; - char *sep = skip_buf_matching (ptr, lim, newline_or_blank, false); - extract_field (line, ptr, sep - ptr); - ptr = sep; - } - } + while ((ptr = skip_buf_matching (ptr, lim, newline_or_blank, true)) < lim) + { + char *sep = skip_buf_matching (ptr, lim, newline_or_blank, false); + extract_field (line, ptr, sep - ptr); + ptr = sep; + } else { if (tab.ch != '\n') for (char *sep; - ((sep = skip_buf_matching (ptr, lim, eq_tab, false)) - < lim); + (sep = skip_buf_matching (ptr, lim, eq_tab, false)) < lim; ptr = sep + mcel_scan (sep, lim).len) extract_field (line, ptr, sep - ptr); diff --git a/tests/misc/join-utf8.sh b/tests/misc/join-utf8.sh index a2bc3b1e5..0e56ff5ae 100755 --- a/tests/misc/join-utf8.sh +++ b/tests/misc/join-utf8.sh @@ -29,7 +29,10 @@ multiplication_sign='×' en_dash='–' old_Persian_word_divider='𐏐' +tflag= + for s in \ + ' ' \ "$vertical_line" \ "$multiplication_sign" \ "$en_dash" \ @@ -37,10 +40,11 @@ for s in \ do printf '0%sA\n1%sa\n2%sb\n4%sc\n' "$s" "$s" "$s" "$s" >a || framework_failure_ - printf '0%sB\n1%sd\n3%se\n4%sf\n' "$s" "$s" "$s" "$s" >b || + printf '0%sB\n1%sd\n3%se\n4%s\0f\n' "$s" "$s" "$s" "$s" >b || framework_failure_ - join -t"$s" -a1 -a2 -eouch -o0,1.2,2.2 a b >out || fail=1 - printf '0%sA%sB\n1%sa%sd\n2%sb%souch\n3%souch%se\n4%sc%sf\n' \ + join $tflag$s -a1 -a2 -eouch -o0,1.2,2.2 a b >out || fail=1 + tflag=-t + printf '0%sA%sB\n1%sa%sd\n2%sb%souch\n3%souch%se\n4%sc%s\0f\n' \ "$s" "$s" "$s" "$s" "$s" "$s" "$s" "$s" "$s" "$s" >exp || framework_failure_ compare exp out || fail=1 |
