Module Name: src Committed By: rillig Date: Sun Jul 26 20:21:31 UTC 2020
Modified Files: src/usr.bin/make: arch.c cond.c nonints.h suff.c var.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/usr.bin/make/arch.c cvs rdiff -u -r1.81 -r1.82 src/usr.bin/make/cond.c cvs rdiff -u -r1.85 -r1.86 src/usr.bin/make/nonints.h cvs rdiff -u -r1.89 -r1.90 src/usr.bin/make/suff.c cvs rdiff -u -r1.330 -r1.331 src/usr.bin/make/var.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/arch.c diff -u src/usr.bin/make/arch.c:1.74 src/usr.bin/make/arch.c:1.75 --- src/usr.bin/make/arch.c:1.74 Sun Jul 19 12:26:17 2020 +++ src/usr.bin/make/arch.c Sun Jul 26 20:21:31 2020 @@ -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 @@ Arch_ParseArchive(char **linePtr, Lst no */ int length; void *freeIt; - char *result; + const char *result; result = Var_Parse(cp, ctxt, VARE_UNDEFERR|VARE_WANTRES, &length, &freeIt); @@ -299,7 +299,7 @@ Arch_ParseArchive(char **linePtr, Lst no */ int length; void *freeIt; - char *result; + const char *result; result = Var_Parse(cp, ctxt, VARE_UNDEFERR|VARE_WANTRES, &length, &freeIt); Index: src/usr.bin/make/cond.c diff -u src/usr.bin/make/cond.c:1.81 src/usr.bin/make/cond.c:1.82 --- src/usr.bin/make/cond.c:1.81 Sun Jul 19 12:35:30 2020 +++ src/usr.bin/make/cond.c Sun Jul 26 20:21:31 2020 @@ -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 CondDoMake(int, const cha 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 @@ CondGetArg(Boolean doEval, char **linePt 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 @@ CondDoCommands(int argLen MAKE_ATTR_UNUS *----------------------------------------------------------------------- */ static Boolean -CondCvtArg(char *str, double *value) +CondCvtArg(const char *str, double *value) { char *eptr, ech; unsigned long l_val; @@ -525,12 +525,12 @@ CondCvtArg(char *str, double *value) *----------------------------------------------------------------------- */ /* 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 @@ CondGetString(Boolean doEval, Boolean *q } } 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 @@ static Token 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 @@ get_mpt_arg(Boolean doEval, char **lineP */ 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 @@ get_mpt_arg(Boolean doEval, char **lineP } /* 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++; /* Index: src/usr.bin/make/nonints.h diff -u src/usr.bin/make/nonints.h:1.85 src/usr.bin/make/nonints.h:1.86 --- src/usr.bin/make/nonints.h:1.85 Sun Jul 26 19:55:24 2020 +++ src/usr.bin/make/nonints.h Sun Jul 26 20:21:31 2020 @@ -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_Set(const char *, const char *, 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 *); Index: src/usr.bin/make/suff.c diff -u src/usr.bin/make/suff.c:1.89 src/usr.bin/make/suff.c:1.90 --- src/usr.bin/make/suff.c:1.89 Sun Jul 19 12:26:17 2020 +++ src/usr.bin/make/suff.c Sun Jul 26 20:21:31 2020 @@ -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 @@ SuffExpandChildren(LstNode cln, GNode *p * 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; Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.330 src/usr.bin/make/var.c:1.331 --- src/usr.bin/make/var.c:1.330 Sun Jul 26 19:55:24 2020 +++ src/usr.bin/make/var.c Sun Jul 26 20:21:31 2020 @@ -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 @@ ParseModifierPart(const char **tstr, int Buf_AddByte(&buf, *cp); } else { if (eflags & VARE_WANTRES) { - char *cp2; + const char *cp2; int len; void *freeIt; @@ -2145,7 +2145,7 @@ ApplyModifier_Defined(const char *mod, A * 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 @@ ApplyModifiers(char *nstr, const char *t * We may have some complex modifiers in a variable. */ void *freeIt; - char *rval; + const char *rval; int rlen; int c; @@ -3383,7 +3383,7 @@ cleanup: *----------------------------------------------------------------------- */ /* 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 @@ Var_Parse(const char * const str, GNode */ 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 @@ Var_Parse(const char * const str, GNode 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 @@ char * 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 */