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): mark result of Var_Parse as const



details:   https://anonhg.NetBSD.org/src/rev/86ca246b63f0
branches:  trunk
changeset: 936427:86ca246b63f0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 26 19:44:04 2020 +0000

description:
make(1): mark result of Var_Parse as const

Var_Parse can return either a string literal or an allocated string.  The
former must not be modified by the caller.  If the string is allocated,
it is returned in freePtr as well, but only for freeing it after use.

diffstat:

 usr.bin/make/nonints.h |   4 ++--
 usr.bin/make/var.c     |  35 ++++++++++++++++++-----------------
 2 files changed, 20 insertions(+), 19 deletions(-)

diffs (138 lines):

diff -r 369ce7353b7b -r 86ca246b63f0 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Jul 26 19:36:24 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Jul 26 19:44:04 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.83 2020/07/26 18:11:12 rillig Exp $      */
+/*     $NetBSD: nonints.h,v 1.84 2020/07/26 19:44:04 rillig Exp $      */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -191,7 +191,7 @@
 void Var_Append(const char *, const char *, GNode *);
 Boolean Var_Exists(const char *, GNode *);
 char *Var_Value(const char *, GNode *, char **);
-char *Var_Parse(const char *, GNode *, VarEvalFlags, int *, void **);
+const char *Var_Parse(const char *, GNode *, VarEvalFlags, int *, void **);
 char *Var_Subst(const char *, const char *, GNode *, VarEvalFlags);
 char *Var_GetTail(const char *);
 char *Var_GetHead(const char *);
diff -r 369ce7353b7b -r 86ca246b63f0 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Jul 26 19:36:24 2020 +0000
+++ b/usr.bin/make/var.c        Sun Jul 26 19:44:04 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.328 2020/07/26 19:36:24 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.329 2020/07/26 19:44:04 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.328 2020/07/26 19:36:24 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.329 2020/07/26 19:44:04 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.328 2020/07/26 19:36:24 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.329 2020/07/26 19:44:04 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1838,7 +1838,6 @@
                    Buf_AddByte(&buf, *cp);
            } else {
                if (eflags & VARE_WANTRES) {
-                   char   *cp2;
                    int     len;
                    void   *freeIt;
 
@@ -1847,8 +1846,9 @@
                     * delimiter, assume it's a variable
                     * substitution and recurse.
                     */
-                   cp2 = Var_Parse(cp, ctxt, errnum | (eflags & VARE_WANTRES),
-                                   &len, &freeIt);
+                   VarEvalFlags sub_eflags = errnum | (eflags & VARE_WANTRES);
+                   const char *cp2 = Var_Parse(cp, ctxt, sub_eflags,
+                                               &len, &freeIt);
                    Buf_AddStr(&buf, cp2);
                    free(freeIt);
                    cp += len - 1;
@@ -2145,11 +2145,11 @@
             * If unescaped dollar sign, assume it's a
             * variable substitution and recurse.
             */
-           char    *cp2;
            int     len;
            void    *freeIt;
 
-           cp2 = Var_Parse(st->cp, st->ctxt, neflags, &len, &freeIt);
+           const char *cp2 = Var_Parse(st->cp, st->ctxt, neflags,
+                                       &len, &freeIt);
            Buf_AddStr(&buf, cp2);
            free(freeIt);
            st->cp += len - 1;
@@ -3077,11 +3077,11 @@
             * We may have some complex modifiers in a variable.
             */
            void *freeIt;
-           char *rval;
            int rlen;
            int c;
 
-           rval = Var_Parse(p, st.ctxt, st.eflags, &rlen, &freeIt);
+           const char *rval = Var_Parse(p, st.ctxt, st.eflags,
+                                        &rlen, &freeIt);
 
            /*
             * If we have not parsed up to st.endc or ':',
@@ -3383,7 +3383,7 @@
  *-----------------------------------------------------------------------
  */
 /* coverity[+alloc : arg-*4] */
-char *
+const char *
 Var_Parse(const char * const str, GNode *ctxt, VarEvalFlags flags,
          int *lengthPtr, void **freePtr)
 {
@@ -3436,13 +3436,13 @@
                 */
                switch (str[1]) {
                case '@':
-                   return UNCONST("$(.TARGET)");
+                   return "$(.TARGET)";
                case '%':
-                   return UNCONST("$(.MEMBER)");
+                   return "$(.MEMBER)";
                case '*':
-                   return UNCONST("$(.PREFIX)");
+                   return "$(.PREFIX)";
                case '!':
-                   return UNCONST("$(.ARCHIVE)");
+                   return "$(.ARCHIVE)";
                }
            }
            return (flags & VARE_UNDEFERR) ? var_Error : varNoError;
@@ -3475,7 +3475,8 @@
            if (*tstr == '$') {
                int rlen;
                void *freeIt;
-               char *rval = Var_Parse(tstr, ctxt, flags, &rlen, &freeIt);
+               const char *rval = Var_Parse(tstr, ctxt, flags,
+                                            &rlen, &freeIt);
                if (rval != NULL)
                    Buf_AddStr(&buf, rval);
                free(freeIt);
@@ -3713,7 +3714,7 @@
 Var_Subst(const char *var, const char *str, GNode *ctxt, VarEvalFlags flags)
 {
     Buffer     buf;            /* Buffer for forming things */
-    char       *val;           /* Value to substitute for a variable */
+    const char *val;           /* Value to substitute for a variable */
     int                length;         /* Length of the variable invocation */
     Boolean    trailingBslash; /* variable ends in \ */
     void       *freeIt = NULL; /* Set if it should be freed */



Home | Main Index | Thread Index | Old Index