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): change char * to void * in Var_Value



details:   https://anonhg.NetBSD.org/src/rev/cdd117841603
branches:  trunk
changeset: 945452:cdd117841603
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 30 20:30:44 2020 +0000

description:
make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value.  To do this, no pointer arithmetic is
needed.  Therefore, change to a void pointer, to catch accidental use of
that pointer.

diffstat:

 usr.bin/make/arch.c    |   8 ++++----
 usr.bin/make/compat.c  |  10 +++++-----
 usr.bin/make/cond.c    |   6 +++---
 usr.bin/make/job.c     |   6 +++---
 usr.bin/make/main.c    |  36 +++++++++++++++++++++---------------
 usr.bin/make/make.c    |  12 ++++++------
 usr.bin/make/meta.c    |  29 ++++++++++++++++-------------
 usr.bin/make/nonints.h |   4 ++--
 usr.bin/make/parse.c   |   8 ++++----
 usr.bin/make/suff.c    |   6 +++---
 usr.bin/make/trace.c   |   6 +++---
 usr.bin/make/var.c     |   6 +++---
 12 files changed, 73 insertions(+), 64 deletions(-)

diffs (truncated from 537 to 300 lines):

diff -r 5d30e24bc460 -r cdd117841603 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Fri Oct 30 20:05:00 2020 +0000
+++ b/usr.bin/make/arch.c       Fri Oct 30 20:30:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.148 2020/10/30 16:48:58 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.149 2020/10/30 20:30:44 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.148 2020/10/30 16:48:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.149 2020/10/30 20:30:44 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -861,7 +861,7 @@
 {
     FILE *arch;                /* Stream open to archive, positioned properly */
     struct ar_hdr arh; /* Current header describing member */
-    char *p1, *p2;
+    void *p1, *p2;
 
     arch = ArchFindMember(Var_Value(ARCHIVE, gn, &p1),
                          Var_Value(MEMBER, gn, &p2),
@@ -921,7 +921,7 @@
 {
     struct ar_hdr *arhPtr;     /* Header of desired member */
     time_t modTime;            /* Modification time as an integer */
-    char *p1, *p2;
+    void *p1, *p2;
 
     arhPtr = ArchStatMember(Var_Value(ARCHIVE, gn, &p1),
                            Var_Value(MEMBER, gn, &p2),
diff -r 5d30e24bc460 -r cdd117841603 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Fri Oct 30 20:05:00 2020 +0000
+++ b/usr.bin/make/compat.c     Fri Oct 30 20:30:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.169 2020/10/26 21:34:10 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.170 2020/10/30 20:30:44 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.169 2020/10/26 21:34:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.170 2020/10/30 20:30:44 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -110,7 +110,7 @@
 CompatDeleteTarget(GNode *gn)
 {
     if (gn != NULL && !Targ_Precious(gn)) {
-       char *file_freeIt;
+       void *file_freeIt;
        const char *file = Var_Value(TARGET, gn, &file_freeIt);
 
        if (!opts.noExecute && eunlink(file) != -1) {
@@ -503,7 +503,7 @@
        }
 
        if (Lst_FindDatum(gn->implicitParents, pgn) != NULL) {
-           char *target_freeIt;
+           void *target_freeIt;
            Var_Set(IMPSRC, Var_Value(TARGET, gn, &target_freeIt), pgn);
            bmake_free(target_freeIt);
        }
@@ -597,7 +597,7 @@
        pgn->flags &= ~(unsigned)REMAKE;
     } else {
        if (Lst_FindDatum(gn->implicitParents, pgn) != NULL) {
-           char *target_freeIt;
+           void *target_freeIt;
            const char *target = Var_Value(TARGET, gn, &target_freeIt);
            Var_Set(IMPSRC, target != NULL ? target : "", pgn);
            bmake_free(target_freeIt);
diff -r 5d30e24bc460 -r cdd117841603 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Fri Oct 30 20:05:00 2020 +0000
+++ b/usr.bin/make/cond.c       Fri Oct 30 20:30:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.172 2020/10/30 14:56:23 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.173 2020/10/30 20:30:44 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.172 2020/10/30 14:56:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.173 2020/10/30 20:30:44 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -283,7 +283,7 @@
 static Boolean
 FuncDefined(size_t argLen MAKE_ATTR_UNUSED, const char *arg)
 {
-    char *freeIt;
+    void *freeIt;
     Boolean result = Var_Value(arg, VAR_CMDLINE, &freeIt) != NULL;
     bmake_free(freeIt);
     return result;
diff -r 5d30e24bc460 -r cdd117841603 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Fri Oct 30 20:05:00 2020 +0000
+++ b/usr.bin/make/job.c        Fri Oct 30 20:30:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.295 2020/10/30 15:39:17 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.296 2020/10/30 20:30:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.295 2020/10/30 15:39:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.296 2020/10/30 20:30:44 rillig Exp $");
 
 /* A shell defines how the commands are run.  All commands for a target are
  * written into a single file, which is then given to the shell to execute
@@ -1193,7 +1193,7 @@
      */
     if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands) &&
        (gn->type & OP_SPECIAL) == 0) {
-       char *p1;
+       void *p1;
        /*
         * Make only looks for a .DEFAULT if the node was never the
         * target of an operator, so that's what we do too. If
diff -r 5d30e24bc460 -r cdd117841603 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Fri Oct 30 20:05:00 2020 +0000
+++ b/usr.bin/make/main.c       Fri Oct 30 20:30:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.411 2020/10/30 15:39:17 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.412 2020/10/30 20:30:44 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -118,7 +118,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.411 2020/10/30 15:39:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.412 2020/10/30 20:30:44 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -674,7 +674,7 @@
 Main_ParseArgLine(const char *line)
 {
        Words words;
-       char *p1;
+       void *p1;
        const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
        char *buf;
 
@@ -742,7 +742,7 @@
 static Boolean
 Main_SetVarObjdir(const char *var, const char *suffix)
 {
-       char *path_freeIt;
+       void *path_freeIt;
        const char *path = Var_Value(var, VAR_CMDLINE, &path_freeIt);
        const char *xpath;
        char *xpath_freeIt;
@@ -857,7 +857,7 @@
                bmake_free(evalue);
 
        } else {
-               char *freeIt;
+               void *freeIt;
                const char *value = Var_Value(varname, VAR_GLOBAL, &freeIt);
                printf("%s\n", value ? value : "");
                bmake_free(freeIt);
@@ -1029,7 +1029,7 @@
 HandlePWD(const struct stat *curdir_st)
 {
        char *pwd;
-       char *prefix_freeIt, *makeobjdir_freeIt;
+       void *prefix_freeIt, *makeobjdir_freeIt;
        const char *makeobjdir;
        struct stat pwd_st;
 
@@ -1336,7 +1336,6 @@
 {
        Boolean outOfDate;      /* FALSE if all targets up to date */
        struct stat sa;
-       char *p1;
        const char *machine;
        const char *machine_arch;
        char *syspath = getenv("MAKESYSPATH");
@@ -1461,9 +1460,11 @@
         * in a different format).
         */
 #ifdef POSIX
-       p1 = explode(getenv("MAKEFLAGS"));
-       Main_ParseArgLine(p1);
-       free(p1);
+       {
+           char *p1 = explode(getenv("MAKEFLAGS"));
+           Main_ParseArgLine(p1);
+           free(p1);
+       }
 #else
        Main_ParseArgLine(getenv("MAKE"));
 #endif
@@ -1544,8 +1545,13 @@
 
        MakeMode(NULL);
 
-       Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
-       bmake_free(p1);
+       {
+           void *freeIt;
+           Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &freeIt),
+                      VAR_GLOBAL);
+           bmake_free(freeIt);
+
+       }
 
        InitMaxJobs();
 
@@ -2013,14 +2019,14 @@
 {
     GNode *cache;
     const char *rp;
-    char *cp;
+    void *freeIt;
 
     if (!pathname || !pathname[0])
        return NULL;
 
     cache = get_cached_realpaths();
 
-    if ((rp = Var_Value(pathname, cache, &cp)) != NULL) {
+    if ((rp = Var_Value(pathname, cache, &freeIt)) != NULL) {
        /* a hit */
        strncpy(resolved, rp, MAXPATHLEN);
        resolved[MAXPATHLEN - 1] = '\0';
@@ -2028,7 +2034,7 @@
        Var_Set(pathname, rp, cache);
     } /* else should we negative-cache? */
 
-    bmake_free(cp);
+    bmake_free(freeIt);
     return rp ? resolved : NULL;
 }
 
diff -r 5d30e24bc460 -r cdd117841603 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Fri Oct 30 20:05:00 2020 +0000
+++ b/usr.bin/make/make.c       Fri Oct 30 20:30:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.182 2020/10/30 15:39:17 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.183 2020/10/30 20:30:44 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
 #include    "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.182 2020/10/30 15:39:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.183 2020/10/30 20:30:44 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked = 1;
@@ -569,7 +569,7 @@
 UpdateImplicitParentsVars(GNode *cgn, const char *cname)
 {
     GNodeListNode *ln;
-    char *cpref_freeIt;
+    void *cpref_freeIt;
     const char *cpref = Var_Value(PREFIX, cgn, &cpref_freeIt);
 
     for (ln = cgn->implicitParents->first; ln != NULL; ln = ln->next) {
@@ -615,7 +615,7 @@
     checked++;
 
     {
-       char *cname_freeIt;
+       void *cname_freeIt;
        cname = Var_Value(TARGET, cgn, &cname_freeIt);
        assert(cname_freeIt == NULL);
     }
@@ -779,7 +779,7 @@
 
     if ((cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE)) == 0) {
        const char *child, *allsrc;
-       char *p1 = NULL, *p2 = NULL;
+       void *p1 = NULL, *p2 = NULL;
 
        if (cgn->type & OP_ARCHV)
            child = Var_Value(MEMBER, cgn, &p1);
@@ -855,7 +855,7 @@



Home | Main Index | Thread Index | Old Index