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): clean up unnecessary snprintf and mult...



details:   https://anonhg.NetBSD.org/src/rev/bdbed6bbdb6c
branches:  trunk
changeset: 936109:bdbed6bbdb6c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 19 12:35:30 2020 +0000

description:
make(1): clean up unnecessary snprintf and multi-line function calls

diffstat:

 usr.bin/make/cond.c |  13 +++++--------
 usr.bin/make/main.c |  22 ++++++++--------------
 usr.bin/make/meta.c |   9 +++------
 3 files changed, 16 insertions(+), 28 deletions(-)

diffs (135 lines):

diff -r c2d5e059e173 -r bdbed6bbdb6c usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Jul 19 12:26:17 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Jul 19 12:35:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.80 2020/07/19 12:26:17 rillig Exp $ */
+/*     $NetBSD: cond.c,v 1.81 2020/07/19 12:35:30 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.80 2020/07/19 12:26:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.81 2020/07/19 12:35:30 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.80 2020/07/19 12:26:17 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.81 2020/07/19 12:35:30 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -283,13 +283,10 @@
             * variable, so we don't do it too. Nor do we return an error,
             * though perhaps we should...
             */
-           char        *cp2;
            int         len;
            void        *freeIt;
-
-           cp2 = Var_Parse(cp, VAR_CMD, VARE_UNDEFERR|
-                           (doEval ? VARE_WANTRES : 0),
-                           &len, &freeIt);
+           VarEvalFlags eflags = VARE_UNDEFERR | (doEval ? VARE_WANTRES : 0);
+           char *cp2 = Var_Parse(cp, VAR_CMD, eflags, &len, &freeIt);
            Buf_AddBytes(&buf, strlen(cp2), cp2);
            free(freeIt);
            cp += len;
diff -r c2d5e059e173 -r bdbed6bbdb6c usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sun Jul 19 12:26:17 2020 +0000
+++ b/usr.bin/make/main.c       Sun Jul 19 12:35:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.281 2020/07/19 12:26:17 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.282 2020/07/19 12:35:30 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.281 2020/07/19 12:26:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.282 2020/07/19 12:35:30 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.281 2020/07/19 12:26:17 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.282 2020/07/19 12:35:30 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2039,8 +2039,6 @@
 PrintOnError(GNode *gn, const char *s)
 {
     static GNode *en = NULL;
-    char tmp[64];
-    char *cp;
 
     /* we generally want to keep quiet if a sub-make died */
     if (dieQuietly(gn, -1))
@@ -2061,9 +2059,8 @@
        Var_Delete(".ERROR_CMD", VAR_GLOBAL);
        Lst_ForEach(gn->commands, addErrorCMD, gn);
     }
-    strncpy(tmp, "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
-           sizeof(tmp) - 1);
-    cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARE_WANTRES);
+    const char *expr = "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}";
+    char *cp = Var_Subst(NULL, expr, VAR_GLOBAL, VARE_WANTRES);
     if (cp) {
        if (*cp)
            printf("%s", cp);
@@ -2085,17 +2082,14 @@
 Main_ExportMAKEFLAGS(Boolean first)
 {
     static int once = 1;
-    char tmp[64];
-    char *s;
 
     if (once != first)
        return;
     once = 0;
 
-    strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
-           sizeof(tmp));
-    s = Var_Subst(NULL, tmp, VAR_CMD, VARE_WANTRES);
-    if (s && *s) {
+    const char *expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}";
+    char *s = Var_Subst(NULL, expr, VAR_CMD, VARE_WANTRES);
+    if (s != NULL && s[0] != '\0') {
 #ifdef POSIX
        setenv("MAKEFLAGS", s, 1);
 #else
diff -r c2d5e059e173 -r bdbed6bbdb6c usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Sun Jul 19 12:26:17 2020 +0000
+++ b/usr.bin/make/meta.c       Sun Jul 19 12:35:30 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.87 2020/07/19 12:26:17 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.88 2020/07/19 12:35:30 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -1011,12 +1011,9 @@
     }
 
     if (metaIgnorePatterns) {
-       char *pm;
-
        Var_Set(".p.", p, gn);
-       pm = Var_Subst(NULL,
-                      "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}",
-                      gn, VARE_WANTRES);
+       const char *expr = "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}";
+       char *pm = Var_Subst(NULL, expr, gn, VARE_WANTRES);
        if (*pm) {
 #ifdef DEBUG_META_MODE
            if (DEBUG(META))



Home | Main Index | Thread Index | Old Index