Module Name:    src
Committed By:   rillig
Date:           Sat Aug 29 13:38:48 UTC 2020

Modified Files:
        src/usr.bin/make: arch.c cond.c parse.c suff.c var.c

Log Message:
make(1): trust that Var_Parse never returns NULL

That function is quite long, but all its return paths lead either to the
expanded variable expression, or to var_Error or varNoError.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/usr.bin/make/arch.c src/usr.bin/make/cond.c
cvs rdiff -u -r1.272 -r1.273 src/usr.bin/make/parse.c
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/make/suff.c
cvs rdiff -u -r1.477 -r1.478 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/arch.c
diff -u src/usr.bin/make/arch.c:1.105 src/usr.bin/make/arch.c:1.106
--- src/usr.bin/make/arch.c:1.105	Sat Aug 29 12:20:17 2020
+++ src/usr.bin/make/arch.c	Sat Aug 29 13:38:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.105 2020/08/29 12:20:17 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.106 2020/08/29 13:38:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.105 2020/08/29 12:20:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.106 2020/08/29 13:38:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.105 2020/08/29 12:20:17 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.106 2020/08/29 13:38:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -234,20 +234,19 @@ Arch_ParseArchive(char **linePtr, Lst no
 	     * so we can safely advance beyond it...
 	     */
 	    int 	length;
-	    void	*freeIt;
+	    void	*result_freeIt;
 	    const char	*result;
+	    Boolean isError;
 
 	    result = Var_Parse(cp, ctxt, VARE_UNDEFERR|VARE_WANTRES,
-			       &length, &freeIt);
-	    free(freeIt);
-
-	    if (result == var_Error) {
+			       &length, &result_freeIt);
+	    isError = result == var_Error;
+	    free(result_freeIt);
+	    if (isError)
 		return FALSE;
-	    } else {
-		subLibName = TRUE;
-	    }
 
-	    cp += length-1;
+	    subLibName = TRUE;
+	    cp += length - 1;
 	}
     }
 
@@ -278,17 +277,17 @@ Arch_ParseArchive(char **linePtr, Lst no
 		int 	length;
 		void	*freeIt;
 		const char *result;
+		Boolean isError;
 
 		result = Var_Parse(cp, ctxt, VARE_UNDEFERR|VARE_WANTRES,
 				   &length, &freeIt);
+		isError = result == var_Error;
 		free(freeIt);
 
-		if (result == var_Error) {
+		if (isError)
 		    return FALSE;
-		} else {
-		    doSubst = TRUE;
-		}
 
+		doSubst = TRUE;
 		cp += length;
 	    } else {
 		cp++;
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.105 src/usr.bin/make/cond.c:1.106
--- src/usr.bin/make/cond.c:1.105	Sat Aug 29 10:12:06 2020
+++ src/usr.bin/make/cond.c	Sat Aug 29 13:38:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.105 2020/08/29 10:12:06 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.106 2020/08/29 13:38:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.105 2020/08/29 10:12:06 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.106 2020/08/29 13:38:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.105 2020/08/29 10:12:06 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.106 2020/08/29 13:38:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -683,7 +683,7 @@ get_mpt_arg(Boolean doEval, const char *
      * TOK_TRUE if the resulting string is empty.
      */
     int length;
-    void *freeIt;
+    void *val_freeIt;
     const char *val;
     const char *cp = *linePtr;
 
@@ -691,7 +691,7 @@ get_mpt_arg(Boolean doEval, const char *
     *argPtr = NULL;
 
     val = Var_Parse(cp - 1, VAR_CMD, doEval ? VARE_WANTRES : 0, &length,
-		    &freeIt);
+		    &val_freeIt);
     /*
      * Advance *linePtr to beyond the closing ). Note that
      * we subtract one because 'length' is calculated from 'cp - 1'.
@@ -699,7 +699,7 @@ get_mpt_arg(Boolean doEval, const char *
     *linePtr = cp - 1 + length;
 
     if (val == var_Error) {
-	free(freeIt);
+	free(val_freeIt);
 	return -1;
     }
 
@@ -712,7 +712,7 @@ get_mpt_arg(Boolean doEval, const char *
      * true/false here.
      */
     length = *val ? 2 : 1;
-    free(freeIt);
+    free(val_freeIt);
     return length;
 }
 

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.272 src/usr.bin/make/parse.c:1.273
--- src/usr.bin/make/parse.c:1.272	Sat Aug 29 12:20:17 2020
+++ src/usr.bin/make/parse.c	Sat Aug 29 13:38:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.272 2020/08/29 12:20:17 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.273 2020/08/29 13:38:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.272 2020/08/29 12:20:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.273 2020/08/29 13:38:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.272 2020/08/29 12:20:17 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.273 2020/08/29 13:38:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1238,7 +1238,7 @@ ParseDoDependency(char *line)
 		(void)Var_Parse(cp, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES,
 				&length, &freeIt);
 		free(freeIt);
-		cp += length-1;
+		cp += length - 1;
 	    }
 	}
 

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.135 src/usr.bin/make/suff.c:1.136
--- src/usr.bin/make/suff.c:1.135	Sat Aug 29 13:16:54 2020
+++ src/usr.bin/make/suff.c	Sat Aug 29 13:38:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.135 2020/08/29 13:16:54 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.136 2020/08/29 13:38:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.135 2020/08/29 13:16:54 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.136 2020/08/29 13:38:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.135 2020/08/29 13:16:54 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.136 2020/08/29 13:38:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1333,7 +1333,7 @@ SuffExpandChildren(LstNode cln, GNode *p
 		    void	*freeIt;
 
 		    junk = Var_Parse(cp, pgn, VARE_UNDEFERR|VARE_WANTRES,
-			&len, &freeIt);
+				     &len, &freeIt);
 		    if (junk != var_Error) {
 			cp += len - 1;
 		    }

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.477 src/usr.bin/make/var.c:1.478
--- src/usr.bin/make/var.c:1.477	Sat Aug 29 13:16:54 2020
+++ src/usr.bin/make/var.c	Sat Aug 29 13:38:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.477 2020/08/29 13:16:54 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.478 2020/08/29 13:38:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.477 2020/08/29 13:16:54 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.478 2020/08/29 13:38:48 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.477 2020/08/29 13:16:54 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.478 2020/08/29 13:38:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3079,7 +3079,6 @@ ApplyModifiers(
 	     * we are not interested.
 	     */
 	    int c;
-	    assert(rval != NULL);
 	    if (rval[0] != '\0' &&
 		(c = p[rlen]) != '\0' && c != ':' && c != st.endc) {
 		free(freeIt);
@@ -3374,7 +3373,7 @@ VarIsDynamic(GNode *ctxt, const char *va
  *	freePtr		OUT: Non-NULL if caller should free *freePtr
  *
  * Results:
- *	Returns the value of the variable expression.
+ *	Returns the value of the variable expression, never NULL.
  *	var_Error if there was a parse error and VARE_UNDEFERR was set.
  *	varNoError if there was a parse error and VARE_UNDEFERR was not set.
  *
@@ -3499,8 +3498,7 @@ Var_Parse(const char * const str, GNode 
 		void *freeIt;
 		const char *rval = Var_Parse(tstr, ctxt, eflags, &rlen,
 					     &freeIt);
-		if (rval != NULL)
-		    Buf_AddStr(&namebuf, rval);
+		Buf_AddStr(&namebuf, rval);
 		free(freeIt);
 		tstr += rlen - 1;
 	    } else

Reply via email to