Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): add assertions for non-nullness of str...



details:   https://anonhg.NetBSD.org/src/rev/55a8376f50a6
branches:  trunk
changeset: 942982:55a8376f50a6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 23 08:29:18 2020 +0000

description:
make(1): add assertions for non-nullness of strings

Verified by manually inspecting all call sites.

diffstat:

 usr.bin/make/var.c |  18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diffs (81 lines):

diff -r a4a173597221 -r 55a8376f50a6 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Aug 23 08:26:03 2020 +0000
+++ b/usr.bin/make/var.c        Sun Aug 23 08:29:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.459 2020/08/22 21:42:38 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.460 2020/08/23 08:29:18 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.459 2020/08/22 21:42:38 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.460 2020/08/23 08:29:18 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.459 2020/08/22 21:42:38 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.460 2020/08/23 08:29:18 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -778,6 +778,8 @@
     char *name_freeIt = NULL;
     Var *v;
 
+    assert(val != NULL);
+
     /*
      * We only look for a variable in the given context since anything set
      * here will override anything in a lower context, so there's not much
@@ -928,6 +930,8 @@
     char *name_freeIt = NULL;
     Var *v;
 
+    assert(val != NULL);
+
     if (strchr(name, '$') != NULL) {
        const char *unexpanded_name = name;
        name = name_freeIt = Var_Subst(name, ctxt, VARE_WANTRES);
@@ -1931,9 +1935,9 @@
     const VarEvalFlags eflags;
 
     char *val;                 /* The old value of the expression,
-                                * before applying the modifier */
+                                * before applying the modifier, never NULL */
     char *newVal;              /* The new value of the expression,
-                                * after applying the modifier */
+                                * after applying the modifier, never NULL */
     char missing_delim;                /* For error reporting */
 
     char sep;                  /* Word separator in expansions
@@ -3010,7 +3014,7 @@
 ) {
     ApplyModifiersState st = {
        startc, endc, v, ctxt, eflags, val,
-       NULL,                   /* .newVal */
+       var_Error,              /* .newVal */
        '\0',                   /* .missing_delim */
        ' ',                    /* .sep */
        FALSE                   /* .oneBigWord */
@@ -3021,6 +3025,7 @@
 
     assert(startc == '(' || startc == '{' || startc == '\0');
     assert(endc == ')' || endc == '}' || endc == '\0');
+    assert(val != NULL);
 
     p = *pp;
     while (*p != '\0' && *p != endc) {
@@ -3259,6 +3264,7 @@
     }
 out:
     *pp = p;
+    assert(st.val != NULL);    /* Use var_Error or varNoError instead. */
     return st.val;
 
 bad_modifier:



Home | Main Index | Thread Index | Old Index