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): improve const-correctness in archive h...



details:   https://anonhg.NetBSD.org/src/rev/0e003f12ff46
branches:  trunk
changeset: 936468:0e003f12ff46
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jul 27 19:06:45 2020 +0000

description:
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.

diffstat:

 usr.bin/make/arch.c |  40 ++++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 20 deletions(-)

diffs (118 lines):

diff -r b8ba6c223a77 -r 0e003f12ff46 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Mon Jul 27 18:59:56 2020 +0000
+++ b/usr.bin/make/arch.c       Mon Jul 27 19:06:45 2020 +0000
@@ -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 @@
 #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 @@
  *-----------------------------------------------------------------------
  */
 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 @@
      * 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 @@
            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 @@
                }
            }
            else {
-               if (cp[0] == '/')
-                   cp[0] = '\0';
+               if (nameend[0] == '/')
+                   nameend[0] = '\0';
            }
 #endif
 
@@ -846,12 +847,11 @@
  *-----------------------------------------------------------------------
  */
 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 @@
      * 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)) {



Home | Main Index | Thread Index | Old Index