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 return value of Var_Parse constant



details:   https://anonhg.NetBSD.org/src/rev/e655c06f9610
branches:  trunk
changeset: 936430:e655c06f9610
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 26 20:21:31 2020 +0000

description:
make(1): make return value of Var_Parse constant

This return value is not supposed to be modified since it can be a string
literal.  The modifiable part is returned via freePtr, but only for
freeing, not for actually modifying anything.

diffstat:

 usr.bin/make/arch.c    |  10 +++++-----
 usr.bin/make/cond.c    |  30 +++++++++++++++---------------
 usr.bin/make/nonints.h |   4 ++--
 usr.bin/make/suff.c    |   8 ++++----
 usr.bin/make/var.c     |  26 +++++++++++++-------------
 5 files changed, 39 insertions(+), 39 deletions(-)

diffs (truncated from 304 to 300 lines):

diff -r 0dd5c6e2ae9f -r e655c06f9610 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sun Jul 26 20:04:57 2020 +0000
+++ b/usr.bin/make/arch.c       Sun Jul 26 20:21:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.74 2020/07/19 12:26:17 rillig Exp $ */
+/*     $NetBSD: arch.c,v 1.75 2020/07/26 20:21:31 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.74 2020/07/19 12:26:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.75 2020/07/26 20:21:31 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.74 2020/07/19 12:26:17 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.75 2020/07/26 20:21:31 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -257,7 +257,7 @@
             */
            int         length;
            void        *freeIt;
-           char        *result;
+           const char  *result;
 
            result = Var_Parse(cp, ctxt, VARE_UNDEFERR|VARE_WANTRES,
                               &length, &freeIt);
@@ -299,7 +299,7 @@
                 */
                int     length;
                void    *freeIt;
-               char    *result;
+               const char *result;
 
                result = Var_Parse(cp, ctxt, VARE_UNDEFERR|VARE_WANTRES,
                                   &length, &freeIt);
diff -r 0dd5c6e2ae9f -r e655c06f9610 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Jul 26 20:04:57 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Jul 26 20:21:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.81 2020/07/19 12:35:30 rillig Exp $ */
+/*     $NetBSD: cond.c,v 1.82 2020/07/26 20:21:31 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.81 2020/07/19 12:35:30 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.82 2020/07/26 20:21:31 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.81 2020/07/19 12:35:30 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.82 2020/07/26 20:21:31 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -153,7 +153,7 @@
 static Boolean CondDoExists(int, const char *);
 static Boolean CondDoTarget(int, const char *);
 static Boolean CondDoCommands(int, const char *);
-static Boolean CondCvtArg(char *, double *);
+static Boolean CondCvtArg(const char *, double *);
 static Token CondToken(Boolean);
 static Token CondT(Boolean);
 static Token CondF(Boolean);
@@ -286,7 +286,7 @@
            int         len;
            void        *freeIt;
            VarEvalFlags eflags = VARE_UNDEFERR | (doEval ? VARE_WANTRES : 0);
-           char *cp2 = Var_Parse(cp, VAR_CMD, eflags, &len, &freeIt);
+           const char *cp2 = Var_Parse(cp, VAR_CMD, eflags, &len, &freeIt);
            Buf_AddBytes(&buf, strlen(cp2), cp2);
            free(freeIt);
            cp += len;
@@ -479,7 +479,7 @@
  *-----------------------------------------------------------------------
  */
 static Boolean
-CondCvtArg(char *str, double *value)
+CondCvtArg(const char *str, double *value)
 {
     char *eptr, ech;
     unsigned long l_val;
@@ -525,12 +525,12 @@
  *-----------------------------------------------------------------------
  */
 /* coverity:[+alloc : arg-*2] */
-static char *
+static const char *
 CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS)
 {
     Buffer buf;
-    char *cp;
-    char *str;
+    const char *cp;
+    const char *str;
     int        len;
     int qt;
     char *start;
@@ -626,8 +626,8 @@
        }
     }
  got_str:
-    str = Buf_GetAll(&buf, NULL);
-    *freeIt = str;
+    *freeIt = Buf_GetAll(&buf, NULL);
+    str = *freeIt;
  cleanup:
     Buf_Destroy(&buf, FALSE);
     return str;
@@ -650,8 +650,8 @@
 compare_expression(Boolean doEval)
 {
     Token      t;
-    char       *lhs;
-    char       *rhs;
+    const char *lhs;
+    const char *rhs;
     char       *op;
     void       *lhsFree;
     void       *rhsFree;
@@ -821,7 +821,7 @@
      */
     int            length;
     void    *freeIt;
-    char    *val;
+    const char *val;
     char    *cp = *linePtr;
 
     /* We do all the work here and return the result as the length */
@@ -840,7 +840,7 @@
     }
 
     /* A variable is empty when it just contains spaces... 4/15/92, christos */
-    while (isspace(*(unsigned char *)val))
+    while (isspace((unsigned char)val[0]))
        val++;
 
     /*
diff -r 0dd5c6e2ae9f -r e655c06f9610 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Jul 26 20:04:57 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Jul 26 20:21:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.85 2020/07/26 19:55:24 rillig Exp $      */
+/*     $NetBSD: nonints.h,v 1.86 2020/07/26 20:21:31 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 0dd5c6e2ae9f -r e655c06f9610 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sun Jul 26 20:04:57 2020 +0000
+++ b/usr.bin/make/suff.c       Sun Jul 26 20:21:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.89 2020/07/19 12:26:17 rillig Exp $ */
+/*     $NetBSD: suff.c,v 1.90 2020/07/26 20:21:31 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.89 2020/07/19 12:26:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.90 2020/07/26 20:21:31 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c     8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.89 2020/07/19 12:26:17 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.90 2020/07/26 20:21:31 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1606,7 +1606,7 @@
                     * Start of a variable spec -- contact variable module
                     * to find the end so we can skip over it.
                     */
-                   char        *junk;
+                   const char  *junk;
                    int         len;
                    void        *freeIt;
 
diff -r 0dd5c6e2ae9f -r e655c06f9610 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Jul 26 20:04:57 2020 +0000
+++ b/usr.bin/make/var.c        Sun Jul 26 20:21:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.330 2020/07/26 19:55:24 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.331 2020/07/26 20:21:31 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.330 2020/07/26 19:55:24 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.331 2020/07/26 20:21:31 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.330 2020/07/26 19:55:24 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.331 2020/07/26 20:21:31 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1838,7 +1838,7 @@
                    Buf_AddByte(&buf, *cp);
            } else {
                if (eflags & VARE_WANTRES) {
-                   char   *cp2;
+                   const char *cp2;
                    int     len;
                    void   *freeIt;
 
@@ -2145,7 +2145,7 @@
             * If unescaped dollar sign, assume it's a
             * variable substitution and recurse.
             */
-           char    *cp2;
+           const char *cp2;
            int     len;
            void    *freeIt;
 
@@ -3077,7 +3077,7 @@
             * We may have some complex modifiers in a variable.
             */
            void *freeIt;
-           char *rval;
+           const char *rval;
            int rlen;
            int c;
 
@@ -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,7 @@
            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 +3713,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 */



Home | Main Index | Thread Index | Old Index