]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
join: fix recently introduced NUL bug
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 30 Oct 2023 17:47:34 +0000 (10:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 30 Oct 2023 17:49:44 +0000 (10:49 -0700)
* 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.

src/join.c
tests/misc/join-utf8.sh

index b3ad27465992ec5ccdde2d2d2b96dc74b77c14ab..a89b5de284bbc47cfb60f31318bab605a760ee4a 100644 (file)
@@ -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);
 
index a2bc3b1e510c202a970ceae9699a8b5533061b1d..0e56ff5ae0015f914c2647aa8be9920f379e8c6d 100755 (executable)
@@ -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