]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: Make virStr*cpy*() functions return an int
authorAndrea Bolognani <abologna@redhat.com>
Fri, 20 Jul 2018 07:50:37 +0000 (09:50 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 23 Jul 2018 12:27:30 +0000 (14:27 +0200)
Currently, the functions return a pointer to the
destination buffer on success or NULL on failure.

Not only does this kind of error handling look quite
alien in the context of libvirt, where most functions
return zero on success and a negative int on failure,
but it's also somewhat pointless because unless there's
been a failure the returned pointer will be the same
one passed in by the user, thus offering no additional
value.

Change the functions so that they return an int
instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
41 files changed:
docs/hacking.html.in
src/conf/capabilities.c
src/conf/netdev_vport_profile_conf.c
src/conf/nwfilter_conf.c
src/esx/esx_driver.c
src/esx/esx_vi.c
src/esx/esx_vi_types.c
src/hyperv/hyperv_driver.c
src/libxl/libxl_conf.c
src/locking/lock_driver_sanlock.c
src/lxc/lxc_driver.c
src/nwfilter/nwfilter_dhcpsnoop.c
src/nwfilter/nwfilter_ebiptables_driver.c
src/nwfilter/nwfilter_learnipaddr.c
src/openvz/openvz_conf.c
src/qemu/qemu_agent.c
src/qemu/qemu_command.c
src/qemu/qemu_monitor.c
src/remote/remote_driver.c
src/rpc/virnetlibsshsession.c
src/rpc/virnetsocket.c
src/security/security_apparmor.c
src/security/virt-aa-helper.c
src/test/test_driver.c
src/uml/uml_driver.c
src/util/virfdstream.c
src/util/virhostcpu.c
src/util/virhostmem.c
src/util/virlog.c
src/util/virnetdev.c
src/util/virnetdevbridge.c
src/util/virnetdevtap.c
src/util/virnetdevvportprofile.c
src/util/virstring.c
src/util/virstring.h
src/util/virtypedparam.c
src/xenapi/xenapi_driver.c
src/xenconfig/xen_common.c
src/xenconfig/xen_sxpr.c
src/xenconfig/xen_xl.c
src/xenconfig/xen_xm.c

index fbeea3eb751d16f62cdefc797689a41923e5f208..6c1a5121a4e119f0711119277b0dd69c6e15b61a 100644 (file)
       respectively.  The last argument is the number of bytes
       available in the destination string; if a copy of the source
       string (including a \0) will not fit into the destination, no
-      bytes are copied and the routine returns NULL.  Otherwise, n
+      bytes are copied and the routine returns &lt;0.  Otherwise, n
       bytes from the source are copied into the destination and a
       trailing \0 is appended.
     </p>
index 7a810efa666229e4be2329f0397ceda8ebea5359..0f965002943c54735c834b10f0c4e9181b175ab5 100644 (file)
@@ -1262,7 +1262,7 @@ virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo)
 
     memset(nodeinfo, 0, sizeof(*nodeinfo));
 
-    if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL)
+    if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) < 0)
         return -1;
 
     if (virHostMemGetInfo(&memorybytes, NULL) < 0)
index 58a50793c233428903a6ea697c8a7000d07d3c0b..24052bf78436661fb1467fdd7110ba041f3a3596 100644 (file)
@@ -134,7 +134,7 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
     }
 
     if (virtPortProfileID &&
-        !virStrcpyStatic(virtPort->profileID, virtPortProfileID)) {
+        virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("profileid parameter too long"));
         goto error;
index 36a7315880f8232bd26cfe6235a7e86c14ef7897..120ca5ec14edd81ea007154efde99f8ee470638d 100644 (file)
@@ -966,7 +966,7 @@ ipsetValidator(enum attrDatatype datatype ATTRIBUTE_UNUSED,
 {
     const char *errmsg = NULL;
 
-    if (virStrcpyStatic(item->u.ipset.setname, val->c) == NULL) {
+    if (virStrcpyStatic(item->u.ipset.setname, val->c) < 0) {
         errmsg = _("ipset name is too long");
         goto arg_err_exit;
     }
index edd21b9d285af204ac1a5e8f3a97371ff978351c..cee98ebcafcb85fad59cdab694ebf063c62886d4 100644 (file)
@@ -914,8 +914,8 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
                     goto cleanup;
                 }
 
-                if (!virStrcpyStatic(vCenterIPAddress,
-                                     potentialVCenterIPAddress)) {
+                if (virStrcpyStatic(vCenterIPAddress,
+                                    potentialVCenterIPAddress) < 0) {
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    _("vCenter IP address %s too big for destination"),
                                    potentialVCenterIPAddress);
@@ -1317,7 +1317,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
                 ++ptr;
             }
 
-            if (!virStrcpyStatic(nodeinfo->model, dynamicProperty->val->string)) {
+            if (virStrcpyStatic(nodeinfo->model, dynamicProperty->val->string) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("CPU Model %s too long for destination"),
                                dynamicProperty->val->string);
index d3c4f760baa473ec05de3ece5aa729552d251ccd..727d76e89dd4bdebf8e0dc26d7de080023bae1b9 100644 (file)
@@ -185,7 +185,7 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
     if (VIR_ALLOC_N(buffer, size + 1) < 0)
         return 0;
 
-    if (!virStrncpy(buffer, info, size, size + 1)) {
+    if (virStrncpy(buffer, info, size, size + 1) < 0) {
         VIR_FREE(buffer);
         return 0;
     }
index 315d67d20fe416be6703d1872dc77be124e7976b..7b234f0c87d2740f2388bb1f1d49895bdf01b216 100644 (file)
@@ -1491,7 +1491,7 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime,
         return -1;
     }
 
-    if (!virStrcpyStatic(value, dateTime->value)) {
+    if (virStrcpyStatic(value, dateTime->value) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("xsd:dateTime value '%s' too long for destination"),
                        dateTime->value);
index 6f74adf372921224c21749acc4cf87ee834adff8..6bc4c099e2eeb2bbc313eab8d955eea9c1ce5fe1 100644 (file)
@@ -307,7 +307,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
     }
 
     /* Fill struct */
-    if (virStrcpyStatic(info->model, processorList->data.common->Name) == NULL) {
+    if (virStrcpyStatic(info->model, processorList->data.common->Name) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("CPU model %s too long for destination"),
                        processorList->data.common->Name);
index cda4eb9d3125148d2668701741529a91ec2b65b5..998029dcbbf3e0e45d0172e74af8318d059ec4e2 100644 (file)
@@ -2365,7 +2365,7 @@ libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
         goto cleanup;
     }
 
-    if (virStrcpyStatic(info->model, virArchToString(hostarch)) == NULL) {
+    if (virStrcpyStatic(info->model, virArchToString(hostarch)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("machine type %s too big for destination"),
                        virArchToString(hostarch));
index 3f3a58754191ab3f940433a79ef37bd77cff49a3..3e5f0e37b05ab359b203bd2a022f1bc3c932cb49 100644 (file)
@@ -221,8 +221,8 @@ virLockManagerSanlockSetupLockspace(virLockManagerSanlockDriverPtr driver)
                     VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0)
         goto error;
 
-    if (!virStrcpyStatic(ls.name,
-                         VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE)) {
+    if (virStrcpyStatic(ls.name,
+                        VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Lockspace path '%s' exceeded %d characters"),
                        VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
@@ -231,7 +231,7 @@ virLockManagerSanlockSetupLockspace(virLockManagerSanlockDriverPtr driver)
     }
     ls.host_id = 0; /* Doesn't matter for initialization */
     ls.flags = 0;
-    if (!virStrcpy(ls.host_id_disk.path, path, SANLK_PATH_LEN)) {
+    if (virStrcpy(ls.host_id_disk.path, path, SANLK_PATH_LEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Lockspace path '%s' exceeded %d characters"),
                        path, SANLK_PATH_LEN);
@@ -583,7 +583,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
 
     res->flags = shared ? SANLK_RES_SHARED : 0;
     res->num_disks = 1;
-    if (!virStrcpy(res->name, name, SANLK_NAME_LEN)) {
+    if (virStrcpy(res->name, name, SANLK_NAME_LEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Resource name '%s' exceeds %d characters"),
                        name, SANLK_NAME_LEN);
@@ -592,7 +592,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
 
     for (i = 0; i < nparams; i++) {
         if (STREQ(params[i].key, "path")) {
-            if (!virStrcpy(res->disks[0].path, params[i].value.str, SANLK_PATH_LEN)) {
+            if (virStrcpy(res->disks[0].path, params[i].value.str, SANLK_PATH_LEN) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Lease path '%s' exceeds %d characters"),
                                params[i].value.str, SANLK_PATH_LEN);
@@ -601,7 +601,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
         } else if (STREQ(params[i].key, "offset")) {
             res->disks[0].offset = params[i].value.ul;
         } else if (STREQ(params[i].key, "lockspace")) {
-            if (!virStrcpy(res->lockspace_name, params[i].value.str, SANLK_NAME_LEN)) {
+            if (virStrcpy(res->lockspace_name, params[i].value.str, SANLK_NAME_LEN) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Resource lockspace '%s' exceeds %d characters"),
                                params[i].value.str, SANLK_NAME_LEN);
@@ -651,7 +651,7 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDriverPtr driver,
     res->num_disks = 1;
     if (virCryptoHashString(VIR_CRYPTO_HASH_MD5, name, &hash) < 0)
         goto cleanup;
-    if (!virStrcpy(res->name, hash, SANLK_NAME_LEN)) {
+    if (virStrcpy(res->name, hash, SANLK_NAME_LEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("MD5 hash '%s' unexpectedly larger than %d characters"),
                        hash, (SANLK_NAME_LEN - 1));
@@ -661,16 +661,16 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDriverPtr driver,
     if (virAsprintf(&path, "%s/%s",
                     driver->autoDiskLeasePath, res->name) < 0)
         goto cleanup;
-    if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) {
+    if (virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Lease path '%s' exceeds %d characters"),
                        path, SANLK_PATH_LEN);
         goto cleanup;
     }
 
-    if (!virStrcpy(res->lockspace_name,
-                   VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
-                   SANLK_NAME_LEN)) {
+    if (virStrcpy(res->lockspace_name,
+                  VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
+                  SANLK_NAME_LEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Resource lockspace '%s' exceeds %d characters"),
                        VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE, SANLK_NAME_LEN);
index 1fc6c6a7bf844da7e11709d78243eacac9f36363..9b329269a9b7951a2e05ad45f349ff848caa75a1 100644 (file)
@@ -1334,8 +1334,8 @@ static int lxcNodeGetSecurityModel(virConnectPtr conn,
         || caps->host.secModels[0].model == NULL)
         goto cleanup;
 
-    if (!virStrcpy(secmodel->model, caps->host.secModels[0].model,
-                   VIR_SECURITY_MODEL_BUFLEN)) {
+    if (virStrcpy(secmodel->model, caps->host.secModels[0].model,
+                  VIR_SECURITY_MODEL_BUFLEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("security model string exceeds max %d bytes"),
                        VIR_SECURITY_MODEL_BUFLEN - 1);
@@ -1343,8 +1343,8 @@ static int lxcNodeGetSecurityModel(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (!virStrcpy(secmodel->doi, caps->host.secModels[0].doi,
-                   VIR_SECURITY_DOI_BUFLEN)) {
+    if (virStrcpy(secmodel->doi, caps->host.secModels[0].doi,
+                  VIR_SECURITY_DOI_BUFLEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("security DOI string exceeds max %d bytes"),
                        VIR_SECURITY_DOI_BUFLEN-1);
index 533c45f0807e170988e9d5d478c1103fba545fe1..c7fd3705982da0c4cd58a962f7dada4776d0669d 100644 (file)
@@ -595,7 +595,7 @@ virNWFilterSnoopReqNew(const char *ifkey)
 
     req->threadStatus = THREAD_STATUS_NONE;
 
-    if (virStrcpyStatic(req->ifkey, ifkey) == NULL ||
+    if (virStrcpyStatic(req->ifkey, ifkey) < 0||
         virMutexInitRecursive(&req->lock) < 0)
         goto err_free_req;
 
index b19b07c84548cf22efcf389660be7bc158538274..c1feabe4944cc835935c991ae152d3b90fa3f759 100644 (file)
@@ -168,7 +168,7 @@ printVar(virNWFilterVarCombIterPtr vars,
             return -1;
         }
 
-        if (!virStrcpy(buf, val, bufsize)) {
+        if (virStrcpy(buf, val, bufsize) < 0) {
             const char *varName;
 
             varName = virNWFilterVarAccessGetVarName(item->varAccess);
@@ -282,7 +282,7 @@ _printDataType(virNWFilterVarCombIterPtr vars,
     break;
 
     case DATATYPE_IPSETNAME:
-        if (virStrcpy(buf, item->u.ipset.setname, bufsize) == NULL) {
+        if (virStrcpy(buf, item->u.ipset.setname, bufsize) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Buffer to small for ipset name"));
             return -1;
@@ -311,7 +311,7 @@ _printDataType(virNWFilterVarCombIterPtr vars,
 
         flags = virBufferContentAndReset(&vb);
 
-        if (virStrcpy(buf, flags, bufsize) == NULL) {
+        if (virStrcpy(buf, flags, bufsize) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Buffer too small for IPSETFLAGS type"));
             VIR_FREE(flags);
index 7883afbfb217fbf6b0db368ea8cc8e171a1afcfe..6965af26b697219f15056c8e00a81b4120842899 100644 (file)
@@ -170,7 +170,7 @@ virNWFilterLockIface(const char *ifname)
             goto err_exit;
         }
 
-        if (virStrcpyStatic(ifaceLock->ifname, ifname) == NULL) {
+        if (virStrcpyStatic(ifaceLock->ifname, ifname) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("interface name %s does not fit into "
                              "buffer "),
index 5ed2b423cb4fc0af3d1dbb42f21845aacad8e461..07d0e91b248163f8e04a0167617ced304bf6f813 100644 (file)
@@ -274,7 +274,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
                     if (VIR_ALLOC_N(net->ifname, len+1) < 0)
                         goto error;
 
-                    if (virStrncpy(net->ifname, p, len, len+1) == NULL) {
+                    if (virStrncpy(net->ifname, p, len, len+1) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("Network ifname %s too long for destination"), p);
                         goto error;
@@ -291,7 +291,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
                     if (VIR_ALLOC_N(net->data.bridge.brname, len+1) < 0)
                         goto error;
 
-                    if (virStrncpy(net->data.bridge.brname, p, len, len+1) == NULL) {
+                    if (virStrncpy(net->data.bridge.brname, p, len, len+1) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("Bridge name %s too long for destination"), p);
                         goto error;
@@ -304,7 +304,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
                                        _("Wrong length MAC address"));
                         goto error;
                     }
-                    if (virStrncpy(cpy_temp, p, len, sizeof(cpy_temp)) == NULL) {
+                    if (virStrncpy(cpy_temp, p, len, sizeof(cpy_temp)) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("MAC address %s too long for destination"), p);
                         goto error;
@@ -956,7 +956,7 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
         uuidbuf = strtok_r(NULL, "\n", &saveptr);
 
         if (iden != NULL && uuidbuf != NULL && STREQ(iden, "#UUID:")) {
-            if (virStrcpy(uuidstr, uuidbuf, len) == NULL) {
+            if (virStrcpy(uuidstr, uuidbuf, len) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("invalid uuid %s"), uuidbuf);
                 goto cleanup;
index 10c6ef09fa379dce07ccd5f030a9eaa726b8af97..bf08871f18c2f8542e677ce1d70fc30319a9a38f 100644 (file)
@@ -207,7 +207,7 @@ qemuAgentOpenUnix(const char *monitor)
 
     memset(&addr, 0, sizeof(addr));
     addr.sun_family = AF_UNIX;
-    if (virStrcpyStatic(addr.sun_path, monitor) == NULL) {
+    if (virStrcpyStatic(addr.sun_path, monitor) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Agent path %s too big for destination"), monitor);
         goto error;
index ad85e36d6a5609893515450ec2a0e7d3663a8b5c..ae45c45b7fc744dd135c96dbfcc161513ee1b63b 100644 (file)
@@ -4941,7 +4941,7 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev)
 
     memset(&addr, 0, sizeof(addr));
     addr.sun_family = AF_UNIX;
-    if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) == NULL) {
+    if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("UNIX socket path '%s' too long"),
                        dev->data.nix.path);
index 2f3097ca94b4b849237985ffa5e5eaa3b57903e5..6e0644221bb7bdcf837d7ca4f1201b90a54c9f0f 100644 (file)
@@ -353,7 +353,7 @@ qemuMonitorOpenUnix(const char *monitor,
 
     memset(&addr, 0, sizeof(addr));
     addr.sun_family = AF_UNIX;
-    if (virStrcpyStatic(addr.sun_path, monitor) == NULL) {
+    if (virStrcpyStatic(addr.sun_path, monitor) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Monitor path %s too big for destination"), monitor);
         goto error;
index 1d94c2e42dfb32a0944ad1e9a0cba5f6b5b59cde..3b43e219e53e03ce45500bd87b69166a2c10fde0 100644 (file)
@@ -1608,7 +1608,7 @@ remoteNodeGetCPUStats(virConnectPtr conn,
 
     /* Deserialise the result. */
     for (i = 0; i < *nparams; ++i) {
-        if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) == NULL) {
+        if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Stats %s too big for destination"),
                            ret.params.params_val[i].field);
@@ -1672,7 +1672,7 @@ remoteNodeGetMemoryStats(virConnectPtr conn,
 
     /* Deserialise the result. */
     for (i = 0; i < *nparams; ++i) {
-        if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) == NULL) {
+        if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Stats %s too big for destination"),
                            ret.params.params_val[i].field);
index df819f616983db2383fa4dbf5e54b22ac5e8da4f..21eb9f2500183ceb575539a9d29344fac89122a9 100644 (file)
@@ -424,7 +424,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt,
     virConnectCredential retr_passphrase;
     int cred_type;
     char *actual_prompt = NULL;
-    char *p;
+    int p;
 
     /* request user's key password */
     if (!sess->cred || !sess->cred->cb) {
@@ -459,7 +459,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt,
     p = virStrncpy(buf, retr_passphrase.result,
                    retr_passphrase.resultlen, len);
     VIR_DISPOSE_STRING(retr_passphrase.result);
-    if (!p) {
+    if (p < 0) {
         virReportError(VIR_ERR_LIBSSH, "%s",
                        _("passphrase is too long for the buffer"));
         goto error;
index 7087abec9c5dd1e8284961031c79048adc3bcc31..fee61ace60f0dca8b2b86b86189b222178a7751c 100644 (file)
@@ -459,7 +459,7 @@ int virNetSocketNewListenUNIX(const char *path,
     }
 
     addr.data.un.sun_family = AF_UNIX;
-    if (virStrcpyStatic(addr.data.un.sun_path, path) == NULL) {
+    if (virStrcpyStatic(addr.data.un.sun_path, path) < 0) {
         virReportSystemError(ENAMETOOLONG,
                              _("Path %s too long for unix socket"), path);
         goto error;
@@ -690,7 +690,7 @@ int virNetSocketNewConnectUNIX(const char *path,
     }
 
     remoteAddr.data.un.sun_family = AF_UNIX;
-    if (virStrcpyStatic(remoteAddr.data.un.sun_path, path) == NULL) {
+    if (virStrcpyStatic(remoteAddr.data.un.sun_path, path) < 0) {
         virReportSystemError(ENOMEM, _("Path %s too long for unix socket"), path);
         goto cleanup;
     }
index cb41df71a98d5fcdece1b82830b57222772d5b7f..802ca0f14de75136c645b1562a9df8c14df5ae85 100644 (file)
@@ -530,7 +530,7 @@ AppArmorGetSecurityProcessLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
     }
 
     if (virStrcpy(sec->label, profile_name,
-        VIR_SECURITY_LABEL_BUFLEN) == NULL) {
+        VIR_SECURITY_LABEL_BUFLEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("error copying profile name"));
         goto cleanup;
index 952b496f215137dd9347466153bcc7b878b01d79..f104495af0e52ca7ec0ef285dd9315642b240d03 100644 (file)
@@ -1317,7 +1317,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
                 if (strlen(optarg) > PROFILE_NAME_SIZE - 1)
                     vah_error(ctl, 1, _("invalid UUID"));
                 if (virStrcpy((char *)ctl->uuid, optarg,
-                    PROFILE_NAME_SIZE) == NULL)
+                    PROFILE_NAME_SIZE) < 0)
                     vah_error(ctl, 1, _("error copying UUID"));
                 break;
             default:
index f3ed667d688ddfb8f0e7c85f90a182a833a42623..dfca95c9812765cd41f4ee3fc66247c803d1cca3 100644 (file)
@@ -690,7 +690,7 @@ static char *testBuildFilename(const char *relativeTo,
         int totalLen = baseLen + strlen(filename) + 1;
         if (VIR_ALLOC_N(absFile, totalLen) < 0)
             return NULL;
-        if (virStrncpy(absFile, relativeTo, baseLen, totalLen) == NULL) {
+        if (virStrncpy(absFile, relativeTo, baseLen, totalLen) < 0) {
             VIR_FREE(absFile);
             return NULL;
         }
@@ -804,7 +804,7 @@ testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathContextPtr ctxt)
 
     str = virXPathString("string(/node/cpu/model[1])", ctxt);
     if (str != NULL) {
-        if (virStrcpyStatic(nodeInfo->model, str) == NULL) {
+        if (virStrcpyStatic(nodeInfo->model, str) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Model %s too big for destination"), str);
             VIR_FREE(str);
index c77988f01e13714659b2872cf9be84757d50b977..425c0bac04c9003621fe1c5fb309999ff65b02fb 100644 (file)
@@ -850,7 +850,7 @@ static int umlMonitorAddress(const struct uml_driver *driver,
 
     memset(addr, 0, sizeof(*addr));
     addr->sun_family = AF_UNIX;
-    if (virStrcpyStatic(addr->sun_path, sockname) == NULL) {
+    if (virStrcpyStatic(addr->sun_path, sockname) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unix path %s too long for destination"), sockname);
         retval = -1;
@@ -951,7 +951,7 @@ static int umlMonitorCommand(const struct uml_driver *driver,
                              cmd, req.length);
         return -1;
     }
-    if (virStrcpyStatic(req.data, cmd) == NULL) {
+    if (virStrcpyStatic(req.data, cmd) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Command %s too long for destination"), cmd);
         return -1;
index f4777cfd1252b5a9346f676f7c87ec4abbf93a9e..cff40bad25081d45b15d229b6fd2a958178e2f9c 100644 (file)
@@ -1179,11 +1179,11 @@ int virFDStreamConnectUNIX(virStreamPtr st,
     memset(&sa, 0, sizeof(sa));
     sa.sun_family = AF_UNIX;
     if (abstract) {
-        if (virStrcpy(sa.sun_path+1, path, sizeof(sa.sun_path)-1) == NULL)
+        if (virStrcpy(sa.sun_path+1, path, sizeof(sa.sun_path)-1) < 0)
             goto error;
         sa.sun_path[0] = '\0';
     } else {
-        if (virStrcpyStatic(sa.sun_path, path) == NULL)
+        if (virStrcpyStatic(sa.sun_path, path) < 0)
             goto error;
     }
 
index 013c95bb56215c5a6dadf3ab76b64a2d3435f97b..060d38278110cbf9eb32d5ecbfde38e7a47b5566 100644 (file)
@@ -166,7 +166,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
     for (i = 0; cpu_map[i].field != NULL; i++) {
         virNodeCPUStatsPtr param = &params[i];
 
-        if (virStrcpyStatic(param->field, cpu_map[i].field) == NULL) {
+        if (virStrcpyStatic(param->field, cpu_map[i].field) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Field '%s' too long for destination"),
                            cpu_map[i].field);
@@ -933,7 +933,7 @@ virHostCPUStatsAssign(virNodeCPUStatsPtr param,
                       const char *name,
                       unsigned long long value)
 {
-    if (virStrcpyStatic(param->field, name) == NULL) {
+    if (virStrcpyStatic(param->field, name) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("kernel cpu time field is too long"
                                " for the destination"));
index c923a1edf53d69e67600c8072ab7ec9f310370ea..bb8b62653b7f2f2516e1fff86b3a7d2e197b45a6 100644 (file)
@@ -104,7 +104,7 @@ virHostMemGetStatsFreeBSD(virNodeMemoryStatsPtr params,
         }
 
         param = &params[j++];
-        if (virStrcpyStatic(param->field, sysctl_map[i].field) == NULL) {
+        if (virStrcpyStatic(param->field, sysctl_map[i].field) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Field '%s' too long for destination"),
                            sysctl_map[i].field);
@@ -122,7 +122,7 @@ virHostMemGetStatsFreeBSD(virNodeMemoryStatsPtr params,
                                  "vfs.bufspace");
             return -1;
         }
-        if (virStrcpyStatic(param->field, VIR_NODE_MEMORY_STATS_BUFFERS) == NULL) {
+        if (virStrcpyStatic(param->field, VIR_NODE_MEMORY_STATS_BUFFERS) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Field '%s' too long for destination"),
                            VIR_NODE_MEMORY_STATS_BUFFERS);
@@ -224,7 +224,7 @@ virHostMemGetStatsLinux(FILE *meminfo,
             if (STREQ(meminfo_hdr, convp->meminfo_hdr)) {
                 virNodeMemoryStatsPtr param = &params[k++];
 
-                if (virStrcpyStatic(param->field, convp->field) == NULL) {
+                if (virStrcpyStatic(param->field, convp->field) < 0) {
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    "%s", _("Field kernel memory too long for destination"));
                     goto cleanup;
index 9d569057ae61b2fb699ddff2571057e06b74f499..64c0efc1bde3a029c41d2cae7b08fbe6995c4562 100644 (file)
@@ -1026,7 +1026,7 @@ virLogOutputToJournald(virLogSourcePtr source,
 
     memset(&sa, 0, sizeof(sa));
     sa.sun_family = AF_UNIX;
-    if (!virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket"))
+    if (virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket") < 0)
         return;
 
     memset(&mh, 0, sizeof(mh));
index 017786ce43d8a20e54a1916d5798dbd04665cee6..0777ecaf3f4cf2c6f35383b1bb30a0c58f494665 100644 (file)
@@ -138,7 +138,7 @@ static int virNetDevSetupControlFull(const char *ifname,
     if (ifr && ifname) {
         memset(ifr, 0, sizeof(*ifr));
 
-        if (virStrcpyStatic(ifr->ifr_name, ifname) == NULL) {
+        if (virStrcpyStatic(ifr->ifr_name, ifname) < 0) {
             virReportSystemError(ERANGE,
                                  _("Network interface name '%s' is too long"),
                                  ifname);
@@ -593,7 +593,7 @@ int virNetDevSetName(const char* ifname, const char *newifname)
         return -1;
 
 # ifdef HAVE_STRUCT_IFREQ_IFR_NEWNAME
-    if (virStrcpyStatic(ifr.ifr_newname, newifname) == NULL) {
+    if (virStrcpyStatic(ifr.ifr_newname, newifname) < 0) {
         virReportSystemError(ERANGE,
                              _("Network interface name '%s' is too long"),
                              newifname);
@@ -914,7 +914,7 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
 
     memset(&ifreq, 0, sizeof(ifreq));
 
-    if (virStrcpyStatic(ifreq.ifr_name, ifname) == NULL) {
+    if (virStrcpyStatic(ifreq.ifr_name, ifname) < 0) {
         virReportSystemError(ERANGE,
                              _("invalid interface name %s"),
                              ifname);
@@ -1015,7 +1015,7 @@ int virNetDevGetVLanID(const char *ifname, int *vlanid)
         return -1;
     }
 
-    if (virStrcpyStatic(vlanargs.device1, ifname) == NULL) {
+    if (virStrcpyStatic(vlanargs.device1, ifname) < 0) {
         virReportSystemError(ERANGE,
                              _("invalid interface name %s"),
                              ifname);
@@ -2763,7 +2763,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                 mcast->idx = num;
                 break;
             case VIR_MCAST_TYPE_NAME_TOKEN:
-                if (virStrcpy(mcast->name, token, VIR_MCAST_NAME_LEN) == NULL) {
+                if (virStrcpy(mcast->name, token, VIR_MCAST_NAME_LEN) < 0) {
                     virReportSystemError(EINVAL,
                                          _("Failed to parse network device name from '%s'"),
                                          buf);
index cfb7ebae99c740a90f5eeaca916b16d09e24afee..e46ac3585971eb2da83479bd61807c32d2a06912 100644 (file)
@@ -93,7 +93,7 @@ static int virNetDevBridgeCmd(const char *brname,
         return -1;
     }
 
-    if (virStrcpyStatic(ifd.ifd_name, brname) == NULL) {
+    if (virStrcpyStatic(ifd.ifd_name, brname) < 0) {
        virReportSystemError(ERANGE,
                             _("Network interface name '%s' is too long"),
                             brname);
@@ -686,7 +686,7 @@ int virNetDevBridgeAddPort(const char *brname,
     struct ifbreq req;
 
     memset(&req, 0, sizeof(req));
-    if (virStrcpyStatic(req.ifbr_ifsname, ifname) == NULL) {
+    if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) {
         virReportSystemError(ERANGE,
                              _("Network interface name '%s' is too long"),
                              ifname);
@@ -756,7 +756,7 @@ int virNetDevBridgeRemovePort(const char *brname,
     struct ifbreq req;
 
     memset(&req, 0, sizeof(req));
-    if (virStrcpyStatic(req.ifbr_ifsname, ifname) == NULL) {
+    if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) {
         virReportSystemError(ERANGE,
                              _("Network interface name '%s' is too long"),
                              ifname);
index 3118ca18e83bdc39f9911501997cacce13ca1640..d432577c0c5dfb442e89edfb030807fb8b4d31f4 100644 (file)
@@ -270,7 +270,7 @@ int virNetDevTapCreate(char **ifname,
             ifr.ifr_flags |= IFF_VNET_HDR;
 # endif
 
-        if (virStrcpyStatic(ifr.ifr_name, *ifname) == NULL) {
+        if (virStrcpyStatic(ifr.ifr_name, *ifname) < 0) {
             virReportSystemError(ERANGE,
                                  _("Network interface name '%s' is too long"),
                                  *ifname);
@@ -336,7 +336,7 @@ int virNetDevTapDelete(const char *ifname,
     memset(&try, 0, sizeof(struct ifreq));
     try.ifr_flags = IFF_TAP|IFF_NO_PI;
 
-    if (virStrcpyStatic(try.ifr_name, ifname) == NULL) {
+    if (virStrcpyStatic(try.ifr_name, ifname) < 0) {
         virReportSystemError(ERANGE,
                              _("Network interface name '%s' is too long"),
                              ifname);
index 133d962db6b274a85f18f41158c33395d9d6d416..3ebf757fb30564a33efe1a4f97b77629d4a5ff70 100644 (file)
@@ -389,7 +389,7 @@ virNetDevVPortProfileMerge(virNetDevVPortProfilePtr orig,
                            orig->profileID, mods->profileID);
             return -1;
         }
-        if (virStrcpyStatic(orig->profileID, mods->profileID) == NULL) {
+        if (virStrcpyStatic(orig->profileID, mods->profileID) < 0) {
             /* this should never happen - it indicates mods->profileID
              * isn't properly null terminated. */
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -885,8 +885,8 @@ virNetDevVPortProfileGetNthParent(const char *ifname, int ifindex, unsigned int
             break;
 
         if (tb[IFLA_IFNAME]) {
-            if (!virStrcpy(parent_ifname, (char*)RTA_DATA(tb[IFLA_IFNAME]),
-                           IFNAMSIZ)) {
+            if (virStrcpy(parent_ifname, (char*)RTA_DATA(tb[IFLA_IFNAME]),
+                          IFNAMSIZ) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("buffer for root interface name is too small"));
                 rc = -1;
index 31e71d7535a5b447d65c7a3f79d95f1934c87b27..3e2f85465f7dffc89ef10f749cf863d28777600d 100644 (file)
@@ -774,25 +774,23 @@ virAsprintfInternal(bool report,
  * A safe version of strncpy.  The last parameter is the number of bytes
  * available in the destination string, *not* the number of bytes you want
  * to copy.  If the destination is not large enough to hold all n of the
- * src string bytes plus a \0, NULL is returned and no data is copied.
+ * src string bytes plus a \0, <0 is returned and no data is copied.
  * If the destination is large enough to hold the n bytes plus \0, then the
- * string is copied and a pointer to the destination string is returned.
+ * string is copied and 0 is returned.
  */
-char *
+int
 virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
 {
-    char *ret;
-
     if (n > (destbytes - 1))
-        return NULL;
+        return -1;
 
-    ret = strncpy(dest, src, n);
+    strncpy(dest, src, n);
     /* strncpy NULL terminates iff the last character is \0.  Therefore
      * force the last byte to be \0
      */
     dest[n] = '\0';
 
-    return ret;
+    return 0;
 }
 
 /**
@@ -801,11 +799,11 @@ virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
  * A safe version of strcpy.  The last parameter is the number of bytes
  * available in the destination string, *not* the number of bytes you want
  * to copy.  If the destination is not large enough to hold all n of the
- * src string bytes plus a \0, NULL is returned and no data is copied.
+ * src string bytes plus a \0, <0 is returned and no data is copied.
  * If the destination is large enough to hold the source plus \0, then the
- * string is copied and a pointer to the destination string is returned.
+ * string is copied and 0 is returned.
  */
-char *
+int
 virStrcpy(char *dest, const char *src, size_t destbytes)
 {
     return virStrncpy(dest, src, strlen(src), destbytes);
index 14948fdf1cb09fb195bf4e36ee282a38098b3879..125fd4eeded03151ff6e704da014e3420a6c6f31 100644 (file)
@@ -127,9 +127,9 @@ void virSkipSpacesBackwards(const char *str, char **endp)
 
 bool virStringIsEmpty(const char *str);
 
-char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
+int virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
     ATTRIBUTE_RETURN_CHECK;
-char *virStrcpy(char *dest, const char *src, size_t destbytes)
+int virStrcpy(char *dest, const char *src, size_t destbytes)
     ATTRIBUTE_RETURN_CHECK;
 # define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest))
 
index 2452628cdbcd76b2b7db80eba42580fd11d028ef..cfaa0dd9555d5e934039f2819ca484eaa6372519 100644 (file)
@@ -86,7 +86,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
         if (VIR_RESIZE_N(keys, nkeysalloc, nkeys, 1) < 0)
             goto cleanup;
 
-        if (virStrcpyStatic(keys[nkeys].field, name) == NULL) {
+        if (virStrcpyStatic(keys[nkeys].field, name) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Field name '%s' too long"), name);
             goto cleanup;
@@ -222,7 +222,7 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
 
     va_start(ap, type);
 
-    if (virStrcpyStatic(param->field, name) == NULL) {
+    if (virStrcpyStatic(param->field, name) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
                        name);
         goto cleanup;
@@ -279,7 +279,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, const char *name,
         goto cleanup;
     }
 
-    if (virStrcpyStatic(param->field, name) == NULL) {
+    if (virStrcpyStatic(param->field, name) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
                        name);
         goto cleanup;
@@ -1413,7 +1413,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr remote_params,
         virTypedParameterRemotePtr remote_param = remote_params + i;
 
         if (virStrcpyStatic(param->field,
-                            remote_param->field) == NULL) {
+                            remote_param->field) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("parameter %s too big for destination"),
                            remote_param->field);
index f4375c587429f92d6058369d3d9d23285054f515..34f9e2c717b66069f0cbd45c44d8904818618fd9 100644 (file)
@@ -430,9 +430,9 @@ xenapiNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
     if (xen_host_cpu_get_all(session, &host_cpu_set)) {
         host_cpu = host_cpu_set->contents[0];
         xen_host_cpu_get_modelname(session, &modelname, host_cpu);
-        if (!virStrncpy(info->model, modelname,
-                        MIN(strlen(modelname), LIBVIRT_MODELNAME_LEN - 1),
-                        LIBVIRT_MODELNAME_LEN)) {
+        if (virStrncpy(info->model, modelname,
+                       MIN(strlen(modelname), LIBVIRT_MODELNAME_LEN - 1),
+                       LIBVIRT_MODELNAME_LEN) < 0) {
             virReportOOMError();
             xen_host_cpu_set_free(host_cpu_set);
             VIR_FREE(modelname);
index 815ccd030e3c022d6fbfc8c701b001cbd44e9009..fdca9845aa544a0a8041927339395a35b1f4c57a 100644 (file)
@@ -410,7 +410,7 @@ xenParsePCI(char *entry)
         return NULL;
     if (!(nextkey = strchr(key, ':')))
         return NULL;
-    if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) {
+    if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Domain %s too big for destination"), key);
         return NULL;
@@ -419,7 +419,7 @@ xenParsePCI(char *entry)
     key = nextkey + 1;
     if (!(nextkey = strchr(key, ':')))
         return NULL;
-    if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) {
+    if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Bus %s too big for destination"), key);
         return NULL;
@@ -428,7 +428,7 @@ xenParsePCI(char *entry)
     key = nextkey + 1;
     if (!(nextkey = strchr(key, '.')))
         return NULL;
-    if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) {
+    if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Slot %s too big for destination"), key);
         return NULL;
@@ -437,7 +437,7 @@ xenParsePCI(char *entry)
     key = nextkey + 1;
     if (strlen(key) != 1)
         return NULL;
-    if (virStrncpy(func, key, 1, sizeof(func)) == NULL) {
+    if (virStrncpy(func, key, 1, sizeof(func)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Function %s too big for destination"), key);
         return NULL;
@@ -669,7 +669,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
             char vfb[MAX_VFB];
             char *key = vfb;
 
-            if (virStrcpyStatic(vfb, list->list->str) == NULL) {
+            if (virStrcpyStatic(vfb, list->list->str) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("VFB %s too big for destination"),
                                list->list->str);
@@ -880,7 +880,7 @@ xenParseVif(char *entry, const char *vif_typename)
 
         if (STRPREFIX(key, "mac=")) {
             int len = nextkey ? (nextkey - data) : strlen(data);
-            if (virStrncpy(mac, data, len, sizeof(mac)) == NULL) {
+            if (virStrncpy(mac, data, len, sizeof(mac)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("MAC address %s too big for destination"),
                                data);
@@ -888,7 +888,7 @@ xenParseVif(char *entry, const char *vif_typename)
             }
         } else if (STRPREFIX(key, "bridge=")) {
             int len = nextkey ? (nextkey - data) : strlen(data);
-            if (virStrncpy(bridge, data, len, sizeof(bridge)) == NULL) {
+            if (virStrncpy(bridge, data, len, sizeof(bridge)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Bridge %s too big for destination"),
                                data);
@@ -901,7 +901,7 @@ xenParseVif(char *entry, const char *vif_typename)
                 return NULL;
         } else if (STRPREFIX(key, "model=")) {
             int len = nextkey ? (nextkey - data) : strlen(data);
-            if (virStrncpy(model, data, len, sizeof(model)) == NULL) {
+            if (virStrncpy(model, data, len, sizeof(model)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Model %s too big for destination"),
                                data);
@@ -909,7 +909,7 @@ xenParseVif(char *entry, const char *vif_typename)
             }
         } else if (STRPREFIX(key, "type=")) {
             int len = nextkey ? (nextkey - data) : strlen(data);
-            if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+            if (virStrncpy(type, data, len, sizeof(type)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Type %s too big for destination"),
                                data);
@@ -917,7 +917,7 @@ xenParseVif(char *entry, const char *vif_typename)
             }
         } else if (STRPREFIX(key, "vifname=")) {
             int len = nextkey ? (nextkey - data) : strlen(data);
-            if (virStrncpy(vifname, data, len, sizeof(vifname)) == NULL) {
+            if (virStrncpy(vifname, data, len, sizeof(vifname)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Vifname %s too big for destination"),
                                data);
@@ -925,14 +925,14 @@ xenParseVif(char *entry, const char *vif_typename)
             }
         } else if (STRPREFIX(key, "ip=")) {
             int len = nextkey ? (nextkey - data) : strlen(data);
-            if (virStrncpy(ip, data, len, sizeof(ip)) == NULL) {
+            if (virStrncpy(ip, data, len, sizeof(ip)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("IP %s too big for destination"), data);
                 return NULL;
             }
         } else if (STRPREFIX(key, "rate=")) {
             int len = nextkey ? (nextkey - data) : strlen(data);
-            if (virStrncpy(rate, data, len, sizeof(rate)) == NULL) {
+            if (virStrncpy(rate, data, len, sizeof(rate)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("rate %s too big for destination"), data);
                 return NULL;
index e868c05695e38b48a2191158460e840a3f223d59..af6316e7d055e11bdbbd2c83262f1aa8caf77442 100644 (file)
@@ -740,7 +740,7 @@ xenParseSxprSound(virDomainDefPtr def,
                 len = (offset2 - offset);
             else
                 len = strlen(offset);
-            if (virStrncpy(model, offset, len, sizeof(model)) == NULL) {
+            if (virStrncpy(model, offset, len, sizeof(model)) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Sound model %s too big for destination"),
                                offset);
index bc3191ad5ea645e0a46d2cfbb99533be41e51ca4..19b6604e0522a92ceeef1c7d17d45b242fc622f2 100644 (file)
@@ -480,7 +480,7 @@ xenParseXLVnuma(virConfPtr conf,
                     if (STRPREFIX(str, "pnode")) {
                         unsigned int cellid;
 
-                        if (!virStrcpyStatic(vtoken, data)) {
+                        if (virStrcpyStatic(vtoken, data) < 0) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu pnode '%s' too long for destination"),
                                            vnodeCnt, data);
@@ -496,7 +496,7 @@ xenParseXLVnuma(virConfPtr conf,
                         }
                         pnode = cellid;
                     } else if (STRPREFIX(str, "size")) {
-                        if (!virStrcpyStatic(vtoken, data)) {
+                        if (virStrcpyStatic(vtoken, data) < 0) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu size '%s' too long for destination"),
                                            vnodeCnt, data);
@@ -509,7 +509,7 @@ xenParseXLVnuma(virConfPtr conf,
                         virDomainNumaSetNodeMemorySize(numa, vnodeCnt, (kbsize * 1024));
 
                     } else if (STRPREFIX(str, "vcpus")) {
-                        if (!virStrcpyStatic(vtoken, data)) {
+                        if (virStrcpyStatic(vtoken, data) < 0) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu vcpus '%s' too long for destination"),
                                            vnodeCnt, data);
@@ -526,7 +526,7 @@ xenParseXLVnuma(virConfPtr conf,
                         size_t i, ndistances;
                         unsigned int value;
 
-                        if (!virStrcpyStatic(vtoken, data)) {
+                        if (virStrcpyStatic(vtoken, data) < 0) {
                             virReportError(VIR_ERR_INTERNAL_ERROR,
                                            _("vnuma vnode %zu vdistances '%s' too long for destination"),
                                            vnodeCnt, data);
@@ -900,7 +900,7 @@ xenParseXLUSBController(virConfPtr conf, virDomainDefPtr def)
 
                 if (STRPREFIX(key, "type=")) {
                     int len = nextkey ? (nextkey - data) : strlen(data);
-                    if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+                    if (virStrncpy(type, data, len, sizeof(type)) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("type %s invalid"),
                                        data);
@@ -908,7 +908,7 @@ xenParseXLUSBController(virConfPtr conf, virDomainDefPtr def)
                     }
                 } else if (STRPREFIX(key, "version=")) {
                     int len = nextkey ? (nextkey - data) : strlen(data);
-                    if (virStrncpy(version, data, len, sizeof(version)) == NULL) {
+                    if (virStrncpy(version, data, len, sizeof(version)) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("version %s invalid"),
                                        data);
@@ -918,7 +918,7 @@ xenParseXLUSBController(virConfPtr conf, virDomainDefPtr def)
                         goto skipusbctrl;
                 } else if (STRPREFIX(key, "ports=")) {
                     int len = nextkey ? (nextkey - data) : strlen(data);
-                    if (virStrncpy(ports, data, len, sizeof(ports)) == NULL) {
+                    if (virStrncpy(ports, data, len, sizeof(ports)) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("version %s invalid"),
                                        data);
@@ -1002,7 +1002,7 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
 
                 if (STRPREFIX(key, "hostbus=")) {
                     int len = nextkey ? (nextkey - data) : strlen(data);
-                    if (virStrncpy(bus, data, len, sizeof(bus)) == NULL) {
+                    if (virStrncpy(bus, data, len, sizeof(bus)) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("bus %s too big for destination"),
                                        data);
@@ -1010,7 +1010,7 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
                     }
                 } else if (STRPREFIX(key, "hostaddr=")) {
                     int len = nextkey ? (nextkey - data) : strlen(data);
-                    if (virStrncpy(device, data, len, sizeof(device)) == NULL) {
+                    if (virStrncpy(device, data, len, sizeof(device)) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("device %s too big for destination"),
                                        data);
@@ -1078,7 +1078,7 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
 
                 if (STRPREFIX(key, "connection=")) {
                     int len = nextkey ? (nextkey - data) : strlen(data);
-                    if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+                    if (virStrncpy(type, data, len, sizeof(type)) < 0) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("connection %s too big"), data);
                         goto skipchannel;
index ef52cf425052c432d93949ac97ae3ba92082de13..7b60f25ec1c21612f3347ecfb1ed50ff24011267 100644 (file)
@@ -159,7 +159,7 @@ xenParseXMDisk(char *entry, int hvm)
         goto error;
 
     if (virStrncpy(disk->dst, head, offset - head,
-                   (offset - head) + 1) == NULL) {
+                   (offset - head) + 1) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Dest file %s too big for destination"), head);
         goto error;