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): don't modify GNode name while rebuildi...



details:   https://anonhg.NetBSD.org/src/rev/5f8ee05be088
branches:  trunk
changeset: 941544:5f8ee05be088
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 24 03:30:25 2020 +0000

description:
make(1): don't modify GNode name while rebuilding the suffix graph

diffstat:

 usr.bin/make/suff.c |  45 ++++++++++++++++++++++-----------------------
 1 files changed, 22 insertions(+), 23 deletions(-)

diffs (103 lines):

diff -r 4c7b441e7ec9 -r 5f8ee05be088 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Oct 24 03:18:22 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Oct 24 03:30:25 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.220 2020/10/24 03:01:19 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.221 2020/10/24 03:30:25 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -129,7 +129,7 @@
 #include "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.220 2020/10/24 03:01:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.221 2020/10/24 03:30:25 rillig Exp $");
 
 #define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
 #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
@@ -244,11 +244,11 @@
  * Results:
  *     NULL if it ain't, pointer to the start of suffix in str if it is.
  */
-static char *
-SuffSuffGetSuffix(const Suff *s, size_t nameLen, char *nameEnd)
+static const char *
+SuffSuffGetSuffix(const Suff *s, size_t nameLen, const char *nameEnd)
 {
-    char *p1;                  /* Pointer into suffix name */
-    char *p2;                  /* Pointer into string being examined */
+    const char *p1;            /* Pointer into suffix name */
+    const char *p2;            /* Pointer into string being examined */
 
     if (nameLen < s->nameLen)
        return NULL;            /* this string is shorter than the suffix */
@@ -273,18 +273,24 @@
 }
 
 static Suff *
-FindSuffByName(const char *name)
+FindSuffByNameLen(const char *name, size_t nameLen)
 {
     SuffListNode *ln;
 
     for (ln = sufflist->first; ln != NULL; ln = ln->next) {
        Suff *suff = ln->datum;
-       if (strcmp(suff->name, name) == 0)
+       if (suff->nameLen == nameLen && memcmp(suff->name, name, nameLen) == 0)
            return suff;
     }
     return NULL;
 }
 
+static Suff *
+FindSuffByName(const char *name)
+{
+    return FindSuffByNameLen(name, strlen(name));
+}
+
 static GNode *
 FindTransformByName(const char *name)
 {
@@ -608,17 +614,16 @@
 static void
 SuffRebuildGraph(GNode *transform, Suff *suff)
 {
-    char *name = transform->name;
+    const char *name = transform->name;
     size_t nameLen = strlen(name);
-    char *prefixName;
-    const char *suffixName;
+    const char *toName;
 
     /*
      * First see if it is a transformation from this suffix.
      */
-    suffixName = SuffStrIsPrefix(suff->name, name);
-    if (suffixName != NULL) {
-       Suff *to = FindSuffByName(suffixName);
+    toName = SuffStrIsPrefix(suff->name, name);
+    if (toName != NULL) {
+       Suff *to = FindSuffByName(toName);
        if (to != NULL) {
            /* Link in and return, since it can't be anything else. */
            SuffInsert(to->children, suff);
@@ -630,15 +635,9 @@
     /*
      * Not from, maybe to?
      */
-    prefixName = SuffSuffGetSuffix(suff, nameLen, name + nameLen);
-    if (prefixName != NULL) {
-       Suff *from;
-
-       /* Null-terminate the source suffix in order to find it. */
-       /* XXX: don't modify strings, not even temporarily */
-       prefixName[0] = '\0';
-       from = FindSuffByName(name);
-       prefixName[0] = suff->name[0];  /* restore */
+    toName = SuffSuffGetSuffix(suff, nameLen, name + nameLen);
+    if (toName != NULL) {
+       Suff *from = FindSuffByNameLen(name, (size_t)(toName - name));
 
        if (from != NULL) {
            /* establish the proper relationship */



Home | Main Index | Thread Index | Old Index