bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] Get rid of superfluous variables in stem tracking


From: Jouke Witteveen
Subject: [PATCH 1/2] Get rid of superfluous variables in stem tracking
Date: Sat, 12 Oct 2019 13:10:30 +0200
User-agent: Mutt/1.12.2 (2019-09-21)

---
Some minor things I came across when working on a fix for [SV 54161],
which I'll send next.

Sure, the comments say that we should get rid of stem_str, but the
reality is that this variable is probably here to stay. Using it for
constructing the stem makes the kinship to another place where the same
thing happens (see next mail) clearer.

 src/implicit.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/implicit.c b/src/implicit.c
index 707eff5..7bdc8ba 100644
--- a/src/implicit.c
+++ b/src/implicit.c
@@ -443,7 +443,6 @@ pattern_search (struct file *file, int archive,
           unsigned int deps_found = 0;
           /* NPTR points to the part of the prereq we haven't processed.  */
           const char *nptr = 0;
-          const char *dir = NULL;
           int order_only = 0;
           unsigned int matches;
 
@@ -478,7 +477,6 @@ pattern_search (struct file *file, int archive,
                   memcpy (pathdir, filename, pathlen);
                   pathdir[pathlen] = '\0';
                 }
-              dir = pathdir;
             }
 
           if (stemlen > GET_PATH_MAX)
@@ -646,7 +644,7 @@ pattern_search (struct file *file, int archive,
                       /* Parse the expanded string. */
                       struct dep *dp = PARSE_FILE_SEQ (&p, struct dep,
                                                        order_only ? MAP_NUL : 
MAP_PIPE,
-                                                       add_dir ? dir : NULL, 
PARSEFS_NONE);
+                                                       add_dir ? pathdir : 
NULL, PARSEFS_NONE);
                       *dptr = dp;
 
                       for (d = dp; d != NULL; d = d->next)
@@ -931,17 +929,13 @@ pattern_search (struct file *file, int archive,
     }
   else
     {
-      size_t dirlen = (lastslash + 1) - filename;
-      char *sp;
-
       /* We want to prepend the directory from
          the original FILENAME onto the stem.  */
-      fullstemlen = dirlen + stemlen;
-      sp = alloca (fullstemlen + 1);
-      memcpy (sp, filename, dirlen);
-      memcpy (sp + dirlen, stem, stemlen);
-      sp[fullstemlen] = '\0';
-      file->stem = strcache_add (sp);
+      fullstemlen = pathlen + stemlen;
+      memcpy (stem_str, filename, pathlen);
+      memcpy (stem_str + pathlen, stem, stemlen);
+      stem_str[fullstemlen] = '\0';
+      file->stem = strcache_add (stem_str);
     }
 
   file->cmds = rule->cmds;
-- 
2.23.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]