Module Name: src Committed By: rillig Date: Sat Aug 1 09:08:17 UTC 2020
Modified Files: src/usr.bin/make: main.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.287 -r1.288 src/usr.bin/make/main.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/main.c diff -u src/usr.bin/make/main.c:1.287 src/usr.bin/make/main.c:1.288 --- src/usr.bin/make/main.c:1.287 Sat Aug 1 08:55:28 2020 +++ src/usr.bin/make/main.c Sat Aug 1 09:08:17 2020 @@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #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 @@ Main_SetObjdir(const char *fmt, ...) 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; }