filevercmp: fix regression
authorKamil Dudka <kdudka@redhat.com>
Thu, 9 Apr 2009 11:22:23 +0000 (13:22 +0200)
committerJim Meyering <meyering@redhat.com>
Thu, 9 Apr 2009 12:01:50 +0000 (14:01 +0200)
ChangeLog
lib/filevercmp.c
tests/test-filevercmp.c

index e4c9bf6..0e45e71 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-04-09  Kamil Dudka  <kdudka@redhat.com>
+
+       Fix regression in 'filevercmp' module. Thanks Sven Joachim
+       for reporting it.
+       * lib/filevercmp.c: Special handle for "", "." and "..".
+       * tests/test-filevercmp.c: Enlarge the set suite.
+
 2009-04-07  Jim Meyering  <meyering@redhat.com>
 
        useless-if-before-free: show how to remove braced useless free, too
index 99c07db..caa4891 100644 (file)
@@ -135,14 +135,19 @@ filevercmp (const char *s1, const char *s2)
   if (simple_cmp == 0)
     return 0;
 
-  /* handle hidden files */
-  while (*s1 == '.' || *s2 == '.')
-    {
-      if (*s1 != *s2)
-       return *s1 - *s2;
-      s1++;
-      s2++;
-    }
+  /* special handle for "", "." and ".." */
+  if (!*s1)
+    return -1;
+  if (!*s2)
+    return 1;
+  if (0 == strcmp (".", s1))
+    return -1;
+  if (0 == strcmp (".", s2))
+    return 1;
+  if (0 == strcmp ("..", s1))
+    return -1;
+  if (0 == strcmp ("..", s2))
+    return 1;
 
   /* "cut" file suffixes */
   s1_pos = s1;
index 9933b8a..700e182 100644 (file)
@@ -37,6 +37,7 @@
 /* set of well sorted examples */
 static const char *const examples[] =
 {
+  "",
   ".",
   "..",
   ".a~",
@@ -73,6 +74,7 @@ static const char *const examples[] =
   "nss_ldap-1.0-0.1a.tar.gz",
   "nss_ldap-10beta1.fc8.tar.gz",
   "nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild",
+  "#.b#",
   NULL
 };