Module Name:    src
Committed By:   rillig
Date:           Sat Aug  1 07:29:04 UTC 2020

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

Log Message:
make(1): use better variable names in Var_Exists

Calling strchr just to initialize a variable to NULL is not as
straight-forward as possible.

The unspecific variable name cp made it unnecessarily difficult to
understand its purpose.


To generate a diff of this commit:
cvs rdiff -u -r1.372 -r1.373 src/usr.bin/make/var.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/var.c
diff -u src/usr.bin/make/var.c:1.372 src/usr.bin/make/var.c:1.373
--- src/usr.bin/make/var.c:1.372	Sat Aug  1 07:14:04 2020
+++ src/usr.bin/make/var.c	Sat Aug  1 07:29:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.372 2020/08/01 07:14:04 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.373 2020/08/01 07:29:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.372 2020/08/01 07:14:04 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.373 2020/08/01 07:29:04 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.372 2020/08/01 07:14:04 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.373 2020/08/01 07:29:04 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -990,13 +990,12 @@ Var_Append(const char *name, const char 
 Boolean
 Var_Exists(const char *name, GNode *ctxt)
 {
-    Var		  *v;
-    char          *cp;
+    char *name_freeIt = NULL;
+    if (strchr(name, '$') != NULL)
+	name = name_freeIt = Var_Subst(name, ctxt, VARE_WANTRES);
 
-    if ((cp = strchr(name, '$')) != NULL)
-	cp = Var_Subst(name, ctxt, VARE_WANTRES);
-    v = VarFind(cp ? cp : name, ctxt, FIND_CMD | FIND_GLOBAL | FIND_ENV);
-    free(cp);
+    Var *v = VarFind(name, ctxt, FIND_CMD | FIND_GLOBAL | FIND_ENV);
+    free(name_freeIt);
     if (v == NULL)
 	return FALSE;
 

Reply via email to