bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: "(GalaxyMaster)" <galaxy@openwall.com.au>
To: bug-gnulib@gnu.org
Subject: filevercmp incompatible change?
Date: Sat, 28 Jan 2023 14:58:04 +0000	[thread overview]
Message-ID: <01000185f8e2b1b4-becc9439-2f82-4857-a302-55cda9e1574e-000000@email.amazonses.com> (raw)

Hello,

[I am not subscribed, so please CC me if you need any further info]

I think the following commit introduced a behavioural change that was not
intended: https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=1ba2b66ea45f9bc43cdc0f6f93efa59157d2b2ba

coreutils 9.1 are supplied with the previous version of that file and passes
the following test (which relies on filevercmp()):
===
galaxy@apollo:~/ls-test $ ~/rpm-work/BUILD/coreutils-9.1/src/ls -v -A .A .Z .a .z .zz~ .zz .zz.~1~ .0 .9 .zz.0 0 9 A Z a z zz~ zz zz.~1~ zz.0 | cat
.A
.Z
.a
.z
.zz~
.zz
.zz.~1~
.0
.9
.zz.0
0
9
A
Z
a
z
zz~
zz
zz.~1~
zz.0
galaxy@apollo:~/ls-test $
===

if I simply replace the filevercmp.c in coreutil's source tree with the one
from GNU gnulib and rebuild ls, the order changes:
===
galaxy@apollo:~/ls-test $ ~/rpm-work/BUILD/coreutils-9.1/src/ls -v -A .A .Z .a .z .zz~ .zz .zz.~1~ .0 .9 .zz.0 0 9 A Z a z zz~ zz zz.~1~ zz.0 | cat
.0
.9
.A
.Z
.a
.z
.zz~
.zz
.zz.~1~
.zz.0
0
9
A
Z
a
z
zz~
zz
zz.~1~
zz.0
galaxy@apollo:~/ls-test $
===

I am not very familiar with the version sorting (which was promoted by Debian
and seems to be widely adopted), but I believe the current version in GNU
gnulib is not following it and also it is worth mentioning that the coreutils
test was crafted by hand, so the order of the first example seems to be the
expected one.

The difference between two versions is very subtle (I am only including the
chunk with the real change):
===
[galaxy@apollo lib]$ diff -puN filevercmp.c{.included,}
--- filevercmp.c.included	2022-04-08 21:22:26.000000000 +1000
+++ filevercmp.c	2023-01-29 01:34:51.381264202 +1100
@@ -36,20 +37,22 @@ static idx_t
 file_prefixlen (char const *s, ptrdiff_t *len)
 {
   size_t n = *len;  /* SIZE_MAX if N == -1.  */
+  idx_t prefixlen = 0;

-  for (idx_t i = 0; ; i++)
+  for (idx_t i = 0; ; )
     {
-      idx_t prefixlen = i;
-      while (i + 1 < n && s[i] == '.' && (c_isalpha (s[i + 1])
-                                          || s[i + 1] == '~'))
-        for (i += 2; i < n && (c_isalnum (s[i]) || s[i] == '~'); i++)
-          continue;
-
       if (*len < 0 ? !s[i] : i == n)
         {
           *len = i;
           return prefixlen;
         }
+
+      i++;
+      prefixlen = i;
+      while (i + 1 < n && s[i] == '.' && (c_isalpha (s[i + 1])
+                                          || s[i + 1] == '~'))
+        for (i += 2; i < n && (c_isalnum (s[i]) || s[i] == '~'); i++)
+          continue;
     }
 }

===

It seems that the order was re-arranged and this triggers a side-effect, IMHO.

-- 
(GM)


             reply	other threads:[~2023-01-28 14:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28 14:58 (GalaxyMaster) [this message]
2023-01-28 15:20 ` filevercmp incompatible change? Bruno Haible
     [not found] <20230128145803.GF15496@mail.openwall.com.au>
2023-01-28 15:18 ` (GalaxyMaster)
2023-01-28 15:26   ` Bruno Haible
2023-01-28 15:39     ` (GalaxyMaster)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01000185f8e2b1b4-becc9439-2f82-4857-a302-55cda9e1574e-000000@email.amazonses.com \
    --to=galaxy@openwall.com.au \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).