Bug w diffutils
Seweryn Habdank-Wojewodzki
habdank at megapolis.pl
Wed Mar 16 23:55:48 CET 2005
Witam serdecznie
W PLD jest dostepny pakiet diffutils w wersji 2.8.4.
Zawiera on blad: nie dziala opcja --ignore-file-name-case.
Znalazlem na sieci jak to poprawic, ale oficjalnego patch'a nie
znalazlem.
Pozdrawiam, Seweryn.
Ps. Ponizej zalaczam tresc e-maila z poprawkami:
I think I've found a bug in the diffutils 2.8.x routines when the option
--ignore-file-name-case
is used. To see the bug, which shows up on both Linux and window
platforms, simply create
two directories each with a single file, so that the files differ in
case.
mkdir bart1
cd bart1
touch treE
cd ..
mkdir bart2
cd bart2
touch TRee
cd ..
Now, when we do the bare diff without any options, we
expect to see the difference:
>diff bart1 bart2
Only in bart2: TRee
Only in bart1: treE
This is OK. However, when we run it with the --ignore-file-name-case
option,
we should NOT see any printing from diff at all. However, we do!
>diff --ignore-file-name-case bart1 bart2
Only in bart2: TRee
Only in bart1: treE
OK, so we know there's a bug. I'll do even better. I know why it's
happening
and have tested a "fix". The problem is in the routine compare_names in
dir.c
of the diffutils package:
/* Compare file names, returning a value compatible with strcmp. */
static int
compare_names (char const *name1, char const *name2)
{
if (ignore_file_name_case)
{
int r = strcasecmp (name1, name2);
if (r) <***** PROBLEM!!!
return r;
}
if (locale_specific_sorting)
{
int r;
errno = 0;
r = strcoll (name1, name2);
if (errno)
{
error (0, errno, _("cannot compare file names `%s'
and `%s'"),
name1, name2);
longjmp (failed_strcoll, 1);
}
if (r)
return r;
}
return file_name_cmp (name1, name2);
}
Suppose the two targets to compare are "TRee" and "treE". If
ignore_file_name_case
is true, the call to strcasecmp returns 0, but instead of returning 0 as
the value of compare_names,
we then fall through to call strcoll() or file_name_cmp(), which ARE
case sensitive.
If I delete the "if (r)" so that it looks like:
if (ignore_file_name_case)
{
int r = strcasecmp (name1, name2);
return r;
}
Then it seems to work fine! Hope you can it from here.
More information about the pld-bugs
mailing list