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): trust that Var_Parse never returns NULL



details:   https://anonhg.NetBSD.org/src/rev/cbe3fc32f08b
branches:  trunk
changeset: 975478:cbe3fc32f08b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 29 13:38:48 2020 +0000

description:
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.

diffstat:

 usr.bin/make/arch.c  |  31 +++++++++++++++----------------
 usr.bin/make/cond.c  |  14 +++++++-------
 usr.bin/make/parse.c |   8 ++++----
 usr.bin/make/suff.c  |   8 ++++----
 usr.bin/make/var.c   |  12 +++++-------
 5 files changed, 35 insertions(+), 38 deletions(-)

diffs (262 lines):

diff -r a98006a9caad -r cbe3fc32f08b usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Aug 29 13:32:27 2020 +0000
+++ b/usr.bin/make/arch.c       Sat Aug 29 13:38:48 2020 +0000
@@ -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 @@
             * 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 @@
                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++;
diff -r a98006a9caad -r cbe3fc32f08b usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sat Aug 29 13:32:27 2020 +0000
+++ b/usr.bin/make/cond.c       Sat Aug 29 13:38:48 2020 +0000
@@ -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 @@
      * 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 @@
     *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 @@
     *linePtr = cp - 1 + length;
 
     if (val == var_Error) {
-       free(freeIt);
+       free(val_freeIt);
        return -1;
     }
 
@@ -712,7 +712,7 @@
      * true/false here.
      */
     length = *val ? 2 : 1;
-    free(freeIt);
+    free(val_freeIt);
     return length;
 }
 
diff -r a98006a9caad -r cbe3fc32f08b usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Aug 29 13:32:27 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Aug 29 13:38:48 2020 +0000
@@ -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 @@
                (void)Var_Parse(cp, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES,
                                &length, &freeIt);
                free(freeIt);
-               cp += length-1;
+               cp += length - 1;
            }
        }
 
diff -r a98006a9caad -r cbe3fc32f08b usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Aug 29 13:32:27 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Aug 29 13:38:48 2020 +0000
@@ -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 @@
                    void        *freeIt;
 
                    junk = Var_Parse(cp, pgn, VARE_UNDEFERR|VARE_WANTRES,
-                       &len, &freeIt);
+                                    &len, &freeIt);
                    if (junk != var_Error) {
                        cp += len - 1;
                    }
diff -r a98006a9caad -r cbe3fc32f08b usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Aug 29 13:32:27 2020 +0000
+++ b/usr.bin/make/var.c        Sat Aug 29 13:38:48 2020 +0000
@@ -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 @@
             * 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 @@
  *     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 @@
                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



Home | Main Index | Thread Index | Old Index