[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 3/3] Oddities in dealing with the path of a stem
From: |
Jouke Witteveen |
Subject: |
Re: [PATCH v2 3/3] Oddities in dealing with the path of a stem |
Date: |
Sat, 26 Oct 2019 13:05:18 +0200 |
On 10/26/19, Jouke Witteveen <address@hidden> wrote:
> Make the code match the comments.
> ---
Note that memrchr is a GNU extension, available since glibc 2.1.91 (19
years old). If this particular patch is accepted, we might want to
drop the glibc version check in lib/glob.c.
This patch does fix a bug though. The old code did not implement what
the comment said it did: If a filename with multiple slashes ended in
a slash, the filename was considered not to contain any slashes at
all!
The last line makes sure that we only set pathlen if there is a path.
Previously, we would set the variable to a bogus value if there was no
path.
> src/implicit.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/src/implicit.c b/src/implicit.c
> index e400dc6..f7b8c15 100644
> --- a/src/implicit.c
> +++ b/src/implicit.c
> @@ -266,7 +266,7 @@ pattern_search (struct file *file, int archive,
> /* Set LASTSLASH to point at the last slash in FILENAME
> but not counting any slash at the end. (foo/bar/ counts as
> bar/ in directory foo/, not empty in directory foo/bar/.) */
> - lastslash = strrchr (filename, '/');
> + lastslash = memrchr (filename, '/', namelen - 1);
> #ifdef VMS
> if (lastslash == NULL)
> lastslash = strrchr (filename, ']');
> @@ -279,18 +279,16 @@ pattern_search (struct file *file, int archive,
> /* Handle backslashes (possibly mixed with forward slashes)
> and the case of "d:file". */
> {
> - char *bslash = strrchr (filename, '\\');
> + char *bslash = memrchr (filename, '\\', namelen - 1);
> if (lastslash == 0 || bslash > lastslash)
> lastslash = bslash;
> if (lastslash == 0 && filename[0] && filename[1] == ':')
> lastslash = filename + 1;
> }
> #endif
> - if (lastslash != 0 && lastslash[1] == '\0')
> - lastslash = 0;
> }
>
> - pathlen = lastslash - filename + 1;
> + pathlen = lastslash ? lastslash - filename + 1 : 0;
>
> /* First see which pattern rules match this target and may be
> considered.
> Put them in TRYRULES. */
> --
> 2.23.0
>
>