"comm --check-order" does not detect all cases of misordered input.
$ cat foo1
Reaganomics
Reagan
$ cat foo2
Reaganomics
Reagan
Clinton
$ comm --check-order foo1 foo2
Reaganomics
Reagan
comm: file 2 is not in sorted order
$ comm --check-order foo2 foo1
Reaganomics
Reagan
comm: file 1 is not in sorted order
$ comm --check-order foo1 foo1
Reaganomics
Reagan
As you can see, File foo1 is being considered well-ordered. Likewise this file:
$ cat foo
Reagan
Reaganom
R
Richard
R
Reaganomics
Reagan
$ comm --check-order foo foo
Reagan
Reaganom
R
Richard
R
Reaganomics
Reagan
Attached is a fix. Feel free to add a unit test for this; I'm not familiar
enough with coreutils to do that.
Bruno
2009-03-07 Bruno Haible <[email protected]>
* src/comm.c: Include memcmp2.h.
(check_order): Use memcmp2 instead of memcmp.
* bootstrap.conf (gnulib_modules): Add memcmp2.
--- coreutils-7.1/bootstrap.conf.bak 2009-02-16 14:35:18.000000000 +0100
+++ coreutils-7.1/bootstrap.conf 2009-03-07 13:22:45.000000000 +0100
@@ -69,7 +69,7 @@
long-options lstat malloc
mbrtowc
mbswidth
- memcasecmp mempcpy
+ memcasecmp memcmp2 mempcpy
memrchr mgetgroups
mkancesdirs mkdir mkdir-p mkstemp mktime modechange
mountlist mpsort obstack pathmax perl physmem
--- coreutils-7.1/src/comm.c.bak 2008-11-10 14:17:52.000000000 +0100
+++ coreutils-7.1/src/comm.c 2009-03-07 13:25:55.000000000 +0100
@@ -1,5 +1,5 @@
/* comm -- compare two sorted files line by line.
- Copyright (C) 86, 90, 91, 1995-2005, 2008 Free Software Foundation, Inc.
+ Copyright (C) 86, 90, 91, 1995-2005, 2008-2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
#include "error.h"
#include "quote.h"
#include "stdio--.h"
+#include "memcmp2.h"
#include "xmemcoll.h"
/* The official name of this program (e.g., no `g' prefix). */
@@ -199,10 +200,8 @@
order = xmemcoll (prev->buffer, prev->length - 1,
current->buffer, current->length - 1);
else
- {
- size_t len = min (prev->length, current->length) - 1;
- order = memcmp (prev->buffer, current->buffer, len);
- }
+ order = memcmp2 (prev->buffer, prev->length - 1,
+ current->buffer, current->length - 1);
if (0 < order)
{
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils