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): make Main_SetVarObjdir const-correct a...



details:   https://anonhg.NetBSD.org/src/rev/405e649d51bf
branches:  trunk
changeset: 936650:405e649d51bf
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 01 09:08:17 2020 +0000

description:
make(1): make Main_SetVarObjdir const-correct and use separate variables

The return value of Var_Value should be const char *, but changing that
now would be too large a change.

diffstat:

 usr.bin/make/main.c |  27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diffs (62 lines):

diff -r 01713964d7c2 -r 405e649d51bf usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Aug 01 08:55:28 2020 +0000
+++ b/usr.bin/make/main.c       Sat Aug 01 09:08:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.287 2020/08/01 08:55:28 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.288 2020/08/01 09:08:17 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.287 2020/08/01 08:55:28 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.288 2020/08/01 09:08:17 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.287 2020/08/01 08:55:28 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.288 2020/08/01 09:08:17 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -762,23 +762,24 @@
 static Boolean
 Main_SetVarObjdir(const char *var, const char *suffix)
 {
-       char *p, *path, *xpath;
-
-       if ((path = Var_Value(var, VAR_CMD, &p)) == NULL ||
-           *path == '\0')
+       char *path_freeIt;
+       const char *path = Var_Value(var, VAR_CMD, &path_freeIt);
+       if (path == NULL || path[0] == '\0') {
+               free(path_freeIt);
                return FALSE;
+       }
 
        /* expand variable substitutions */
+       const char *xpath = path;
+       char *xpath_freeIt = NULL;
        if (strchr(path, '$') != 0)
-               xpath = Var_Subst(path, VAR_GLOBAL, VARE_WANTRES);
-       else
-               xpath = path;
+               xpath = xpath_freeIt = Var_Subst(path, VAR_GLOBAL,
+                                                VARE_WANTRES);
 
        (void)Main_SetObjdir("%s%s", xpath, suffix);
 
-       if (xpath != path)
-               free(xpath);
-       free(p);
+       free(xpath_freeIt);
+       free(path_freeIt);
        return TRUE;
 }
 



Home | Main Index | Thread Index | Old Index