summaryrefslogtreecommitdiff
path: root/src/implicit.c
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2019-10-26 12:24:29 +0200
committerPaul Smith <psmith@gnu.org>2019-12-17 15:06:28 -0500
commitc72205b28b93ee546027ad5297ba1771f31256a6 (patch)
tree52353cc828dbb04dbda99b51bf22599ffb945e02 /src/implicit.c
parent057e33d6b5bb41d8e0deed0c5ac4d5d72047e7f4 (diff)
downloadmake-git-c72205b28b93ee546027ad5297ba1771f31256a6.tar.gz
* src/implicit.c (pattern_search): Set lastslash correctly
If filename contained multiple slashes lastslash is wrongly set to 0. * configure.ac: Check for the GNU memrchr() extension function. * src/misc.c (memrchr): Supply memrchr() if not available.
Diffstat (limited to 'src/implicit.c')
-rw-r--r--src/implicit.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/implicit.c b/src/implicit.c
index 7bdc8baf..cd707b28 100644
--- a/src/implicit.c
+++ b/src/implicit.c
@@ -265,7 +265,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, ']');
@@ -278,18 +278,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. */