]> xenbits.xensource.com Git - libvirt.git/commitdiff
src: Use virStrcpyStatic() wherever possible
authorAndrea Bolognani <abologna@redhat.com>
Mon, 16 Jul 2018 14:20:39 +0000 (16:20 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 23 Jul 2018 12:27:21 +0000 (14:27 +0200)
This convenience macro was created for the simple cases
where the length of the source string and the size of the
destination buffer can be figued out with strlen() and
sizeof() respectively, so we should use it wherever
possible instead of open-coding parts of it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
src/conf/nwfilter_conf.c
src/util/virfdstream.c
src/util/virlog.c
src/util/virnetdev.c
src/xenconfig/xen_xl.c

index 706e803a258b1f49c263c8f977a55db258ba7431..36a7315880f8232bd26cfe6235a7e86c14ef7897 100644 (file)
@@ -966,8 +966,7 @@ ipsetValidator(enum attrDatatype datatype ATTRIBUTE_UNUSED,
 {
     const char *errmsg = NULL;
 
-    if (virStrcpy(item->u.ipset.setname, val->c,
-                  sizeof(item->u.ipset.setname)) == NULL) {
+    if (virStrcpyStatic(item->u.ipset.setname, val->c) == NULL) {
         errmsg = _("ipset name is too long");
         goto arg_err_exit;
     }
index 81895599646fd5931248ce5a4c27f961596844dc..f4777cfd1252b5a9346f676f7c87ec4abbf93a9e 100644 (file)
@@ -1183,7 +1183,7 @@ int virFDStreamConnectUNIX(virStreamPtr st,
             goto error;
         sa.sun_path[0] = '\0';
     } else {
-        if (virStrcpy(sa.sun_path, path, sizeof(sa.sun_path)) == NULL)
+        if (virStrcpyStatic(sa.sun_path, path) == NULL)
             goto error;
     }
 
index e008dd9c546a22bc444e64d77b10ab0a5bba2f5d..9d569057ae61b2fb699ddff2571057e06b74f499 100644 (file)
@@ -284,8 +284,7 @@ virLogOnceInit(void)
      */
     r = gethostname(virLogHostname, sizeof(virLogHostname));
     if (r == -1) {
-        ignore_value(virStrcpy(virLogHostname,
-                               "(unknown)", sizeof(virLogHostname)));
+        ignore_value(virStrcpyStatic(virLogHostname, "(unknown)"));
     } else {
         NUL_TERMINATE(virLogHostname);
     }
@@ -1027,7 +1026,7 @@ virLogOutputToJournald(virLogSourcePtr source,
 
     memset(&sa, 0, sizeof(sa));
     sa.sun_family = AF_UNIX;
-    if (!virStrcpy(sa.sun_path, "/run/systemd/journal/socket", sizeof(sa.sun_path)))
+    if (!virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket"))
         return;
 
     memset(&mh, 0, sizeof(mh));
index c20022fbc9477d6a978943412890fae270632ed9..57ebd0ec03cfccb632e65f0f32e476ff5c89e119 100644 (file)
@@ -914,8 +914,7 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
 
     memset(&ifreq, 0, sizeof(ifreq));
 
-    if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
-                   sizeof(ifreq.ifr_name)) == NULL) {
+    if (virStrcpyStatic(ifreq.ifr_name, ifname) == NULL) {
         virReportSystemError(ERANGE,
                              _("invalid interface name %s"),
                              ifname);
index f0d9177cec197f616447d0a72e24ebc32d0aa3e3..807fe621d6ebf7d9aad25b0387630e89bbc8f6b5 100644 (file)
@@ -475,15 +475,12 @@ xenParseXLVnuma(virConfPtr conf,
                 data++;
 
                 if (*data) {
-                    size_t len;
                     char vtoken[64];
 
                     if (STRPREFIX(str, "pnode")) {
                         unsigned int cellid;
 
-                        len = strlen(data);
-                        if (!virStrncpy(vtoken, data,
-                                        len, sizeof(vtoken))) {
+                        if (!virStrcpyStatic(vtoken, data)) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu pnode '%s' too long for destination"),
                                            vnodeCnt, data);
@@ -499,9 +496,7 @@ xenParseXLVnuma(virConfPtr conf,
                         }
                         pnode = cellid;
                     } else if (STRPREFIX(str, "size")) {
-                        len = strlen(data);
-                        if (!virStrncpy(vtoken, data,
-                                        len, sizeof(vtoken))) {
+                        if (!virStrcpyStatic(vtoken, data)) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu size '%s' too long for destination"),
                                            vnodeCnt, data);
@@ -514,9 +509,7 @@ xenParseXLVnuma(virConfPtr conf,
                         virDomainNumaSetNodeMemorySize(numa, vnodeCnt, (kbsize * 1024));
 
                     } else if (STRPREFIX(str, "vcpus")) {
-                        len = strlen(data);
-                        if (!virStrncpy(vtoken, data,
-                                        len, sizeof(vtoken))) {
+                        if (!virStrcpyStatic(vtoken, data)) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu vcpus '%s' too long for destination"),
                                            vnodeCnt, data);
@@ -533,9 +526,7 @@ xenParseXLVnuma(virConfPtr conf,
                         size_t i, ndistances;
                         unsigned int value;
 
-                        len = strlen(data);
-                        if (!virStrncpy(vtoken, data,
-                                        len, sizeof(vtoken))) {
+                        if (!virStrcpyStatic(vtoken, data)) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu vdistances '%s' too long for destination"),
                                            vnodeCnt, data);