Module Name:    src
Committed By:   rillig
Date:           Mon Nov 23 22:14:54 UTC 2020

Modified Files:
        src/usr.bin/make: dir.c

Log Message:
make(1): in Dir_Expand, don't re-use local variables

While here, add a few remarks from a previous attempt at flattening
the function.


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/make/dir.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.217 src/usr.bin/make/dir.c:1.218
--- src/usr.bin/make/dir.c:1.217	Mon Nov 23 22:05:58 2020
+++ src/usr.bin/make/dir.c	Mon Nov 23 22:14:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.217 2020/11/23 22:05:58 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.218 2020/11/23 22:14:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -134,7 +134,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.217 2020/11/23 22:05:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.218 2020/11/23 22:14:54 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -790,7 +790,7 @@ Dir_Expand(const char *word, SearchPath 
 
 	/* At this point, the word has a directory component. */
 
-	/* Find the first wildcard in the string. */
+	/* Find the first wildcard in the word. */
 	for (cp = word; *cp != '\0'; cp++)
 		if (*cp == '?' || *cp == '[' || *cp == '*')
 			break;
@@ -828,6 +828,11 @@ Dir_Expand(const char *word, SearchPath 
 		 * It is probably surprising that the directory before a
 		 * wildcard gets added to the path.
 		 */
+		/*
+		 * XXX: Only the first match of the prefix in the path is
+		 * taken, any others are ignored.  The expectation may be
+		 * that the pattern is expanded in the whole path.
+		 */
 		char *dirpath = Dir_FindFile(prefix, path);
 		free(prefix);
 
@@ -840,14 +845,17 @@ Dir_Expand(const char *word, SearchPath 
 		 * XXX: Check whether the above comment is still true.
 		 */
 		if (dirpath != NULL) {
-			char *dp = &dirpath[strlen(dirpath) - 1];
-			if (*dp == '/')
-				*dp = '\0';
-
-			path = Lst_New();
-			(void)Dir_AddDir(path, dirpath);
-			DirExpandPath(cp + 1, path, expansions);
-			Lst_Free(path);
+			SearchPath *partPath;
+
+			char *end = &dirpath[strlen(dirpath) - 1];
+			/* XXX: What about multiple trailing slashes? */
+			if (*end == '/')
+				*end = '\0';
+
+			partPath = Lst_New();
+			(void)Dir_AddDir(partPath, dirpath);
+			DirExpandPath(cp + 1, partPath, expansions);
+			Lst_Free(partPath);
 		}
 	}
 

Reply via email to