bug-coreutils
[Top][All Lists]
Advanced

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

Re: coreutils 5.3.0: cp --parents broken


From: Jim Meyering
Subject: Re: coreutils 5.3.0: cp --parents broken
Date: Tue, 25 Jan 2005 13:31:19 +0100

Andreas Schwab <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>
>> @@ -78,10 +79,49 @@ path_concat (char const *dir, char const
>>    p += needs_separator;
>>
>>    if (base_in_result)
>> -    *base_in_result = p;
>> +    *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase);
>>
>>    p = mempcpy (p, base, baselen);
>>    *p = '\0';
>>
>> +  assert (!base_in_result
>> +      || strcmp (*base_in_result, abase) == 0);
>> +
>
> I think this assertion will trigger if abase starts with multiple slashes,
> which are all stripped by longest_relative_suffix.

You're right.
Here's the fix:

        * path-concat.c: Don't include assert.h.
        (path_concat): Remove assertion that would have triggered
        for ABASE starting with more than one slash.
        Reported by Andreas Schwab.

Index: path-concat.c
===================================================================
RCS file: /fetish/cu/lib/path-concat.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -p -u -r1.22 -r1.23
--- path-concat.c       25 Jan 2005 09:07:49 -0000      1.22
+++ path-concat.c       25 Jan 2005 12:30:01 -0000      1.23
@@ -22,7 +22,6 @@
 #if HAVE_CONFIG_H
 # include <config.h>
 #endif
-# include <assert.h>
 
 /* Specification.  */
 #include "path-concat.h"
@@ -56,7 +55,9 @@ longest_relative_suffix (char const *f)
    in the result, removing any redundant separators.
    In any case, if BASE_IN_RESULT is non-NULL, set
    *BASE_IN_RESULT to point to the copy of ABASE in the returned
-   concatenation.
+   concatenation.  However, if ABASE begins with more than one slash,
+   set *BASE_IN_RESULT to point to the sole corresponding slash that
+   is copied into the result buffer.
 
    Report an error if memory is exhausted.  */
 
@@ -84,9 +85,6 @@ path_concat (char const *dir, char const
   p = mempcpy (p, base, baselen);
   *p = '\0';
 
-  assert (!base_in_result
-         || strcmp (*base_in_result, abase) == 0);
-
   return p_concat;
 }
 
@@ -108,6 +106,7 @@ main ()
       {"/", "/",  "/"},
       {"a", "/",  "a/"},   /* this might deserve a diagnostic */
       {"/a", "/", "/a/"},  /* this might deserve a diagnostic */
+      {"a", "//b",  "a/b"},
     };
   size_t i;
   bool fail = false;




reply via email to

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