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 a 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. Sincerely, Martijn van Duren martijn@openbsd 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])); }
Adding a reference to the bug and patch mentioned in above comment: https://marc.info/?l=openbsd-tech&m=153987435602410 One also gets hit by this bug if one of the file contains blank lines: ``` $ cat 1.txt a b $ cat 2.txt a b $ join 1.txt 2.txt $ ```
Conrad can you commit this? Also reported here: https://lists.gnu.org/archive/html/bug-gnulib/2024-01/msg00028.html
(In reply to Tijl Coosemans from comment #2) No, but you should feel free.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=95bf75895ddcf17402b1f69dce26cb821c922476 commit 95bf75895ddcf17402b1f69dce26cb821c922476 Author: Tijl Coosemans <tijl@FreeBSD.org> AuthorDate: 2024-01-22 10:35:31 +0000 Commit: Tijl Coosemans <tijl@FreeBSD.org> CommitDate: 2024-01-24 09:58:00 +0000 join(1): Fix ordering in case of missing fields The comparison function had the ordering reversed causing join(1) to miss some matching lines. PR: 232405 Submitted by: Martijn van Duren <martijn@openbsd.org> MFC after: 1 week usr.bin/join/join.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=aaefd6898a73528d3888331a51983cbcc9f06125 commit aaefd6898a73528d3888331a51983cbcc9f06125 Author: Tijl Coosemans <tijl@FreeBSD.org> AuthorDate: 2024-01-22 10:35:31 +0000 Commit: Tijl Coosemans <tijl@FreeBSD.org> CommitDate: 2024-01-31 08:53:11 +0000 join(1): Fix ordering in case of missing fields The comparison function had the ordering reversed causing join(1) to miss some matching lines. PR: 232405 Submitted by: Martijn van Duren <martijn@openbsd.org> (cherry picked from commit 95bf75895ddcf17402b1f69dce26cb821c922476) usr.bin/join/join.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=085ab2c143eb5192ea18b8dd52bd8fa69c9f2d06 commit 085ab2c143eb5192ea18b8dd52bd8fa69c9f2d06 Author: Tijl Coosemans <tijl@FreeBSD.org> AuthorDate: 2024-01-22 10:35:31 +0000 Commit: Tijl Coosemans <tijl@FreeBSD.org> CommitDate: 2024-01-31 09:19:00 +0000 join(1): Fix ordering in case of missing fields The comparison function had the ordering reversed causing join(1) to miss some matching lines. PR: 232405 Submitted by: Martijn van Duren <martijn@openbsd.org> (cherry picked from commit 95bf75895ddcf17402b1f69dce26cb821c922476) usr.bin/join/join.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)