Bug 232405 - [patch] join: bug when input does not contain enough columns for the comparison column
Summary: [patch] join: bug when input does not contain enough columns for the comparis...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs mailing list
Keywords: patch
Depends on:
Reported: 2018-10-18 18:35 UTC by Conrad Meyer
Modified: 2018-10-23 06:43 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Conrad Meyer freebsd_committer 2018-10-18 18:35:57 UTC
Martijn van Duren of OpenBSD shares both this bug and a patch.

A similar bug was reported in http://gnats.netbsd.org/1356.

The problem is the following:
$ cat /tmp/z1  
a b
c d
$ cat /tmp/z2
e d
$ ./join -j 2 /tmp/z1 /tmp/z2
$ ./join.patch -j 2 /tmp/z1 /tmp/z2
d c e

The problem is that when the first line is compared the second file
is being slurped instead of the first file.


Martijn van Duren

Index: join.c
--- join.c      (revision 331931)
+++ join.c      (working copy)
@@ -394,9 +394,9 @@
 cmp(LINE *lp1, u_long fieldno1, LINE *lp2, u_long fieldno2)
        if (lp1->fieldcnt <= fieldno1)
-               return (lp2->fieldcnt <= fieldno2 ? 0 : 1);
+               return (lp2->fieldcnt <= fieldno2 ? 0 : -1);
        if (lp2->fieldcnt <= fieldno2)
-               return (-1);
+               return (1);
        return (mbscoll(lp1->fields[fieldno1], lp2->fields[fieldno2]));