]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Take advantage of mempcpy() and stpcpy()
authorPaul Smith <psmith@gnu.org>
Sat, 9 Jul 2022 17:26:30 +0000 (13:26 -0400)
committerPaul Smith <psmith@gnu.org>
Sat, 30 Jul 2022 22:40:21 +0000 (18:40 -0400)
* src/makeint.h (stpcpy): Add missing declaration.
* src/amiga.c (MyExecute): Avoid extra strlen using stpcpy.
* src/function.c (func_shell_base): Ditto.
(func_error): Use memcpy() not strcpy() when we know the length.
* src/job.c (construct_command_argv_internal): Use stpcpy().
* src/main.c (main): Ditto.
(define_makeflags): Ditto.
* src/variable.c (print_target_variables): Use memcpy() when we know
the length.
* src/commands.c (set_file_variables): Use mempcpy().
* src/expand.c (variable_buffer_output): Ditto.
* src/file.c (expand_deps): Ditto.
* src/function.c (abspath): Ditto.
(handle_function): Ditto.
* src/implicit.c (pattern_search): Ditto.
* src/job.c (construct_command_argv_internal): Use mempcpy() and
don't add multiple spaces when there are no shell flags.
* src/main.c (decode_env_switches): Use mempcpy() to simplify.
(define_makeflags): Ditto.
* src/variable.c (selective_vpath_search): Ditto.

src/amiga.c
src/commands.c
src/expand.c
src/file.c
src/function.c
src/implicit.c
src/job.c
src/main.c
src/makeint.h
src/variable.c
src/vpath.c

index ec0ca14320b9da670599e02bab3c20c9aea71c68..10a19cde1c0dfd9281124ffc149faf8e5adb68a3 100644 (file)
@@ -51,9 +51,8 @@ MyExecute (char **argv)
         if (((*aptr)[0] == ';' && !(*aptr)[1]))
         {
             *ptr ++ = '"';
-            strcpy (ptr, *aptr);
-            ptr += strlen (ptr);
-            *ptr ++ = '"';
+            ptr = stpcpy (ptr, *aptr);
+            *(ptr++) = '"';
         }
         else if ((*aptr)[0] == '@' && (*aptr)[1] == '@' && !(*aptr)[2])
         {
@@ -61,10 +60,7 @@ MyExecute (char **argv)
             continue;
         }
         else
-        {
-            strcpy (ptr, *aptr);
-            ptr += strlen (ptr);
-        }
+          ptr = stpcpy (ptr, *aptr);
         *ptr ++ = ' ';
         *ptr = 0;
     }
index 154d5dea50f17b93955153cc8508cb1a8f55b3f0..3dd1953f8ae185f3adeb23f78af6a61a8073d8c6 100644 (file)
@@ -213,8 +213,7 @@ set_file_variables (struct file *file, const char *stem)
 #endif
             len = strlen (c);
 
-          memcpy (cp, c, len);
-          cp += len;
+          cp = mempcpy (cp, c, len);
           *cp++ = FILE_LIST_SEPARATOR;
           if (! (d->changed || always_make_flag))
             qmark_len -= len + 1;       /* Don't space in $? for this one.  */
@@ -284,19 +283,16 @@ set_file_variables (struct file *file, const char *stem)
 
         if (d->ignore_mtime)
           {
-            memcpy (bp, c, len);
-            bp += len;
+            bp = mempcpy (bp, c, len);
             *bp++ = FILE_LIST_SEPARATOR;
           }
         else
           {
-            memcpy (cp, c, len);
-            cp += len;
+            cp = mempcpy (cp, c, len);
             *cp++ = FILE_LIST_SEPARATOR;
             if (d->changed || always_make_flag)
               {
-                memcpy (qp, c, len);
-                qp += len;
+                qp = mempcpy (qp, c, len);
                 *qp++ = FILE_LIST_SEPARATOR;
               }
           }
index 6397bb229d10d0b13aef7ae58d049b8a07884349..6bc2ac59a2108023dbb5069e1ee92ec3e7e43cbc 100644 (file)
@@ -67,8 +67,7 @@ variable_buffer_output (char *ptr, const char *string, size_t length)
       ptr = variable_buffer + offset;
     }
 
-  memcpy (ptr, string, length);
-  return ptr + length;
+  return mempcpy (ptr, string, length);
 }
 
 /* Return a pointer to the beginning of the variable buffer.
index ab46c4a18dda68b43b3ebf92f0a87e15f13c1a98..3960cdabb17ba91391d66dac7f316440205a21b9 100644 (file)
@@ -620,8 +620,7 @@ expand_deps (struct file *f)
 
               while (cs)
                 {
-                  memcpy (s, pcs, cs - pcs);
-                  s += cs - pcs;
+                  s = mempcpy (s, pcs, cs - pcs);
                   *(s++) = '$';
                   *(s++) = '*';
                   pcs = ++cs;
@@ -1273,8 +1272,7 @@ build_target_list (char *value)
                 p = &value[off];
               }
 
-            memcpy (p, f->name, l);
-            p += l;
+            p = mempcpy (p, f->name, l);
             *(p++) = ' ';
           }
       *(p-1) = '\0';
index 9247fc3f60a363c6f083d40378a4efbdf271f98a..1f490fa267d647ae44c5e61d20ae4f96b42b82c6 100644 (file)
@@ -1185,7 +1185,7 @@ func_error (char *o, char **argv, const char *funcname)
       {
         size_t len = strlen (argv[0]);
         char *msg = alloca (len + 2);
-        strcpy (msg, argv[0]);
+        memcpy (msg, argv[0], len);
         msg[len] = '\n';
         msg[len + 1] = '\0';
         outputs (0, msg);
@@ -2060,8 +2060,8 @@ func_shell_base (char *o, char **argv, int trim_newlines)
     {
       strcpy (ptr, *aptr);
       ptr += strlen (ptr) + 1;
-      *ptr ++ = ' ';
-      *ptr = 0;
+      *(ptr++) = ' ';
+      *ptr = '\0';
     }
 
   ptr[-1] = '\n';
@@ -2249,8 +2249,7 @@ abspath (const char *name, char *apath)
           if (dest + len >= apath_limit)
             return NULL;
 
-          dest = memcpy (dest, start, len);
-          dest += len;
+          dest = mempcpy (dest, start, len);
           *dest = '\0';
         }
     }
@@ -2646,9 +2645,8 @@ handle_function (char **op, const char **stringp)
       char *p, *aend;
 
       abeg = xmalloc (len+1);
-      memcpy (abeg, beg, len);
-      abeg[len] = '\0';
-      aend = abeg + len;
+      aend = mempcpy (abeg, beg, len);
+      *aend = '\0';
 
       for (p=abeg, nargs=0; p <= aend; ++argvp)
         {
index a89994b9196fbd1fcf58d2e73dd2fc22d48e0407..d38537268702a1dd55196052891e29bd5eafc71e 100644 (file)
@@ -560,14 +560,9 @@ pattern_search (struct file *file, int archive,
                     {
                       char *o = depname;
                       if (check_lastslash)
-                        {
-                          memcpy (o, filename, pathlen);
-                          o += pathlen;
-                        }
-                      memcpy (o, nptr, cp - nptr);
-                      o += cp - nptr;
-                      memcpy (o, stem, stemlen);
-                      o += stemlen;
+                        o = mempcpy (o, filename, pathlen);
+                      o = mempcpy (o, nptr, cp - nptr);
+                      o = mempcpy (o, stem, stemlen);
                       strcpy (o, cp + 1);
                       is_explicit = 0;
                     }
@@ -651,20 +646,17 @@ pattern_search (struct file *file, int archive,
                         {
                           size_t i = cp - nptr;
                           assert (o + i < dend);
-                          memcpy (o, nptr, i);
-                          o += i;
+                          o = mempcpy (o, nptr, i);
                           if (check_lastslash)
                             {
                               add_dir = 1;
                               assert (o + 5 < dend);
-                              memcpy (o, "$(*F)", 5);
-                              o += 5;
+                              o = mempcpy (o, "$(*F)", 5);
                             }
                           else
                             {
                               assert (o + 2 < dend);
-                              memcpy (o, "$*", 2);
-                              o += 2;
+                              o = mempcpy (o, "$*", 2);
                             }
                           assert (o < dend);
                           ++cp;
@@ -1108,11 +1100,9 @@ pattern_search (struct file *file, int archive,
           struct dep *new = alloc_dep ();
 
           /* GKM FIMXE: handle '|' here too */
-          memcpy (p, rule->targets[ri],
-                  rule->suffixes[ri] - rule->targets[ri] - 1);
-          p += rule->suffixes[ri] - rule->targets[ri] - 1;
-          memcpy (p, file->stem, fullstemlen);
-          p += fullstemlen;
+          p = mempcpy (p, rule->targets[ri],
+                       rule->suffixes[ri] - rule->targets[ri] - 1);
+          p = mempcpy (p, file->stem, fullstemlen);
           memcpy (p, rule->suffixes[ri],
                   rule->lens[ri] - (rule->suffixes[ri] - rule->targets[ri])+1);
           new->name = strcache_add (nm);
index 402d409ff472f1c232dbd0c1da93823042558a4c..8837b744a6b9612e441971a1190636a60f52c1df 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -3413,9 +3413,10 @@ construct_command_argv_internal (char *line, char **restp, const char *shell,
       }
     *(ap++) = ' ';
     if (shellflags)
-      memcpy (ap, shellflags, sflags_len);
-    ap += sflags_len;
-    *(ap++) = ' ';
+      {
+        ap = mempcpy (ap, shellflags, sflags_len);
+        *(ap++) = ' ';
+      }
 #ifdef WINDOWS32
     command_ptr = ap;
 #endif
@@ -3460,8 +3461,7 @@ construct_command_argv_internal (char *line, char **restp, const char *shell,
         else if (unixy_shell && strneq (p, "...", 3))
           {
             /* The case of '...' wildcard again.  */
-            strcpy (ap, "\\.\\.\\");
-            ap += 5;
+            ap = stpcpy (ap, "\\.\\.\\");
             p  += 2;
           }
 #endif
index a999ee89e3aaa6115a589566c41490e368afb0d6..ef2d2c4153e9705e9ac9604cbd19887817bab8bb 100644 (file)
@@ -1977,8 +1977,7 @@ main (int argc, char **argv, char **envp)
       p = endp = value = alloca (len);
       for (i = 0; i < eval_strings->idx; ++i)
         {
-          strcpy (p, "--eval=");
-          p += CSTRLEN ("--eval=");
+          p = stpcpy (p, "--eval=");
           p = quote_for_env (p, eval_strings->list[i]);
           endp = p++;
           *endp = ' ';
@@ -3251,11 +3250,12 @@ decode_env_switches (const char *envar, size_t len)
   const char **argv;
 
   /* Get the variable's value.  */
-  varref[0] = '$';
-  varref[1] = '(';
-  memcpy (&varref[2], envar, len);
-  varref[2 + len] = ')';
-  varref[2 + len + 1] = '\0';
+  p = varref;
+  *(p++) = '$';
+  *(p++) = '(';
+  p = mempcpy (p, envar, len);
+  *(p++) = ')';
+  *p = '\0';
   value = variable_expand (varref);
 
   /* Skip whitespace, and check for an empty value.  */
@@ -3489,8 +3489,7 @@ define_makeflags (int all, int makefile)
         {
           /* Long options require a double-dash.  */
           *p++ = '-';
-          strcpy (p, flags->cs->long_name);
-          p += strlen (p);
+          p = stpcpy (p, flags->cs->long_name);
         }
       /* An omitted optional argument has an ARG of "".  */
       if (flags->arg && flags->arg[0] != '\0')
@@ -3522,8 +3521,7 @@ define_makeflags (int all, int makefile)
   if (eval_strings)
     {
       *p++ = ' ';
-      memcpy (p, evalref, CSTRLEN (evalref));
-      p += CSTRLEN (evalref);
+      p = mempcpy (p, evalref, CSTRLEN (evalref));
     }
 
   if (all)
@@ -3538,13 +3536,10 @@ define_makeflags (int all, int makefile)
 
       if (v && v->value && v->value[0] != '\0')
         {
-          strcpy (p, " -- ");
-          p += 4;
-
+          p = stpcpy (p, " -- ");
           *(p++) = '$';
           *(p++) = '(';
-          memcpy (p, r, l);
-          p += l;
+          p = mempcpy (p, r, l);
           *(p++) = ')';
         }
     }
index d117240b2ae1afccd15f99f5f2d807eb7b7a9124..e355051dbf90f1a1e85da977a0c1daefeb5b8440 100644 (file)
@@ -670,6 +670,11 @@ int strncasecmp (const char *s1, const char *s2, int n);
 void *mempcpy (void *dest, const void *src, size_t n);
 #endif
 
+#if !HAVE_STPCPY
+/* Create our own, in misc.c */
+char *stpcpy (char *dest, const char *src);
+#endif
+
 #define OUTPUT_SYNC_NONE    0
 #define OUTPUT_SYNC_LINE    1
 #define OUTPUT_SYNC_TARGET  2
index c53ce5a74a5a459db2f530201aeb3b903e06e70d..c51f41dcb2ebfc8459833e2b1006a65b65366daf 100644 (file)
@@ -435,8 +435,7 @@ lookup_special_var (struct variable *var)
                 p = &var->value[off];
               }
 
-            memcpy (p, v->name, l);
-            p += l;
+            p = mempcpy (p, v->name, l);
             *(p++) = ' ';
           }
       *(p-1) = '\0';
@@ -1855,7 +1854,7 @@ print_target_variables (const struct file *file)
       size_t l = strlen (file->name);
       char *t = alloca (l + 3);
 
-      strcpy (t, file->name);
+      memcpy (t, file->name, l);
       t[l] = ':';
       t[l+1] = ' ';
       t[l+2] = '\0';
index 336aee2fc8ba769fdaff886757442f4e3ceb172e..203fca1b61dd8fd27416b64145b3c017a9129905 100644 (file)
@@ -379,8 +379,7 @@ selective_vpath_search (struct vpath *path, const char *file,
       size_t vlen = strlen (vpath[i]);
 
       /* Put the next VPATH entry into NAME at P and increment P past it.  */
-      memcpy (p, vpath[i], vlen);
-      p += vlen;
+      p = mempcpy (p, vpath[i], vlen);
 
       /* Add the directory prefix already in *FILE.  */
       if (name_dplen > 0)
@@ -392,8 +391,7 @@ selective_vpath_search (struct vpath *path, const char *file,
           if ((*p != ':') && (*p != ']') && (*p != '>'))
             *p++ = '/';
 #endif
-          memcpy (p, file, name_dplen);
-          p += name_dplen;
+          p = mempcpy (p, file, name_dplen);
         }
 
 #ifdef HAVE_DOS_PATHS