Module Name: src
Committed By: rillig
Date: Mon Jul 27 19:06:45 UTC 2020
Modified Files:
src/usr.bin/make: arch.c
Log Message:
make(1): improve const-correctness in archive handling
The return value of Var_Value must not be modified. Ideally it would be
declared as const char *, but that still takes a while, especially since
much of the make code is not yet covered by the unit tests.
The variable cp had to be changed to const char * as well, and while here
was split up into one variable per actual use case.
To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/make/arch.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.75 src/usr.bin/make/arch.c:1.76
--- src/usr.bin/make/arch.c:1.75 Sun Jul 26 20:21:31 2020
+++ src/usr.bin/make/arch.c Mon Jul 27 19:06:45 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.75 2020/07/26 20:21:31 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.76 2020/07/27 19:06:45 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.75 2020/07/26 20:21:31 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.76 2020/07/27 19:06:45 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.75 2020/07/26 20:21:31 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.76 2020/07/27 19:06:45 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -168,8 +168,9 @@ static int ArchFindArchive(const void *,
#ifdef CLEANUP
static void ArchFree(void *);
#endif
-static struct ar_hdr *ArchStatMember(char *, char *, Boolean);
-static FILE *ArchFindMember(char *, char *, struct ar_hdr *, const char *);
+static struct ar_hdr *ArchStatMember(const char *, const char *, Boolean);
+static FILE *ArchFindMember(const char *, const char *,
+ struct ar_hdr *, const char *);
#if defined(__svr4__) || defined(__SVR4) || defined(__ELF__)
#define SVR4ARCHIVES
static int ArchSVR4Entry(Arch *, char *, size_t, FILE *);
@@ -523,12 +524,11 @@ ArchFindArchive(const void *ar, const vo
*-----------------------------------------------------------------------
*/
static struct ar_hdr *
-ArchStatMember(char *archive, char *member, Boolean hash)
+ArchStatMember(const char *archive, const char *member, Boolean hash)
{
#define AR_MAX_NAME_LEN (sizeof(arh.ar_name)-1)
FILE * arch; /* Stream to archive */
int size; /* Size of archive member */
- char *cp; /* Useful character pointer */
char magic[SARMAG];
LstNode ln; /* Lst member containing archive descriptor */
Arch *ar; /* Archive descriptor */
@@ -543,9 +543,9 @@ ArchStatMember(char *archive, char *memb
* to point 'member' to the final component, if there is one, to make
* the comparisons easier...
*/
- cp = strrchr(member, '/');
- if (cp != NULL) {
- member = cp + 1;
+ const char *base = strrchr(member, '/');
+ if (base != NULL) {
+ member = base + 1;
}
ln = Lst_Find(archives, archive, ArchFindArchive);
@@ -636,10 +636,11 @@ ArchStatMember(char *archive, char *memb
size = (int)strtol(arh.ar_size, NULL, 10);
memcpy(memName, arh.ar_name, sizeof(arh.ar_name));
- for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) {
- continue;
+ char *nameend = memName + AR_MAX_NAME_LEN;
+ while (*nameend == ' ') {
+ nameend--;
}
- cp[1] = '\0';
+ nameend[1] = '\0';
#ifdef SVR4ARCHIVES
/*
@@ -659,8 +660,8 @@ ArchStatMember(char *archive, char *memb
}
}
else {
- if (cp[0] == '/')
- cp[0] = '\0';
+ if (nameend[0] == '/')
+ nameend[0] = '\0';
}
#endif
@@ -846,12 +847,11 @@ ArchSVR4Entry(Arch *ar, char *name, size
*-----------------------------------------------------------------------
*/
static FILE *
-ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr,
+ArchFindMember(const char *archive, const char *member, struct ar_hdr *arhPtr,
const char *mode)
{
FILE * arch; /* Stream to archive */
int size; /* Size of archive member */
- char *cp; /* Useful character pointer */
char magic[SARMAG];
size_t len, tlen;
@@ -876,9 +876,9 @@ ArchFindMember(char *archive, char *memb
* to point 'member' to the final component, if there is one, to make
* the comparisons easier...
*/
- cp = strrchr(member, '/');
- if (cp != NULL) {
- member = cp + 1;
+ const char *base = strrchr(member, '/');
+ if (base != NULL) {
+ member = base + 1;
}
len = tlen = strlen(member);
if (len > sizeof(arhPtr->ar_name)) {