]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
replace open-coded instances of mempcpy
authorCristian Rodríguez <crrodriguez@opensuse.org>
Thu, 19 Jan 2023 18:25:08 +0000 (18:25 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jan 2023 12:52:00 +0000 (13:52 +0100)
lib/buffer.c
lib/canonicalize.c
lib/mbsalign.c
libblkid/src/devno.c
misc-utils/blkid.c
term-utils/agetty.c

index 4bab52c043013e04c3bb1d369f058a269ae56692..fda2fc8aa580ced63733f9efef5c6fa15699cc2b 100644 (file)
@@ -6,6 +6,7 @@
  */
 #include "buffer.h"
 #include "mbsalign.h"
+#include "strutils.h"
 
 void ul_buffer_reset_data(struct ul_buffer *buf)
 {
@@ -147,8 +148,7 @@ int ul_buffer_append_data(struct ul_buffer *buf, const char *data, size_t sz)
        if (!buf->end)
                return -EINVAL; /* make static analyzers happy */
 
-       memcpy(buf->end, data, sz);
-       buf->end += sz;
+       buf->end = mempcpy(buf->end, data, sz);
        *buf->end = '\0';       /* make sure it's terminated */
        return 0;
 }
index ccf52558f71433da6e748f4e48966617a767a8e9..d181a14e9d7ca760412e7650f588003270919552 100644 (file)
@@ -19,6 +19,7 @@
 #include "canonicalize.h"
 #include "pathnames.h"
 #include "all-io.h"
+#include "strutils.h"
 
 /*
  * Converts private "dm-N" names to "/dev/mapper/<name>"
@@ -110,8 +111,7 @@ char *absolute_path(const char *path)
        if (!res)
                return NULL;
 
-       memcpy(p, cwd, csz);
-       p += csz;
+       p = mempcpy(p, cwd, csz);
        *p++ = '/';
        memcpy(p, path, psz + 1);
 
index e251202afbe5e620f472d73a8656b8abebb9c64c..fbb6f157e2b4661ab6844e3a9806ce7b6b609405 100644 (file)
@@ -305,8 +305,7 @@ char *mbs_invalid_encode_to_buffer(const char *s, size_t *width, char *buf)
                        r += 4;
                        *width += 4;
                } else {
-                       memcpy(r, p, len);
-                       r += len;
+                       r = mempcpy(r, p, len);
                        *width += wcwidth(wc);
                }
                p += len;
index 74a0d982e2ce47567d6630a046567cca235e1aba..d35c807da2db0a61f93750af3595c8ae6d96aa49 100644 (file)
@@ -35,6 +35,7 @@
 #include "blkidP.h"
 #include "pathnames.h"
 #include "sysfs.h"
+#include "strutils.h"
 
 static char *blkid_strconcat(const char *a, const char *b, const char *c)
 {
@@ -52,16 +53,13 @@ static char *blkid_strconcat(const char *a, const char *b, const char *c)
        if (!res)
                return NULL;
        if (al) {
-               memcpy(p, a, al);
-               p += al;
+               p = mempcpy(p, a, al);
        }
        if (bl) {
-               memcpy(p, b, bl);
-               p += bl;
+               p = mempcpy(p, b, bl);
        }
        if (cl) {
-               memcpy(p, c, cl);
-               p += cl;
+               p = mempcpy(p, c, cl);
        }
        *p = '\0';
        return res;
index dae2361389a4f21137fd493ead7129117a4dbf72..ef089a8ca312c31d04de695a24f078951fcddd63 100644 (file)
@@ -403,12 +403,10 @@ static int append_str(char **res, size_t *sz, const char *a, const char *b)
        str += *sz;
 
        if (a) {
-               memcpy(str, a, asz);
-               str += asz;
+               str = mempcpy(str, a, asz);
        }
        if (b) {
-               memcpy(str, b, bsz);
-               str += bsz;
+               str = mempcpy(str, b, bsz);
        }
        *str = '\0';
        *sz = len;
index f7a88a3093f4a81122212a4b29524ba244459351..d84047531218605607a65f9aa9ac9a19cc012b28 100644 (file)
@@ -618,13 +618,11 @@ static char *replace_u(char *str, char *username)
 
                if (p != str) {
                        /* copy chars before \u */
-                       memcpy(tp, str, p - str);
-                       tp += p - str;
+                       tp = mempcpy(tp, str, p - str);
                }
                if (usz) {
                        /* copy username */
-                       memcpy(tp, username, usz);
-                       tp += usz;
+                       tp = mempcpy(tp, username, usz);
                }
                if (*(p + 2))
                        /* copy chars after \u + \0 */
@@ -2972,8 +2970,7 @@ static ssize_t append(char *dest, size_t len, const char  *sep, const char *src)
 
        p = dest + dsz;
        if (ssz) {
-               memcpy(p, sep, ssz);
-               p += ssz;
+               p = mempcpy(p, sep, ssz);
        }
        memcpy(p, src, sz);
        *(p + sz) = '\0';