bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug Found in diffutils-2.8.1, diffutils-2.8.4


From: Greg McLaren
Subject: Bug Found in diffutils-2.8.1, diffutils-2.8.4
Date: Mon, 9 Dec 2002 01:19:25 -0800

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]