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

[libvirt] [PATCHv2 03/10] datatypes: avoid redundant __FUNCTION__



virLibConnError already includes __FUNCTION__ in its output, so we
were redundant.  Furthermore, clang warns that __FUNCTION__ is not
a string literal (at least __FUNCTION__ will never contain %, so
it was not a security risk).

* src/datatypes.c: Replace __FUNCTION__ with a descriptive string.
---

This was 2/3 of the original series.  Difference from v1:
more accurate error messages, requested by Matthias

 src/datatypes.c |  127 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 97 insertions(+), 30 deletions(-)

diff --git a/src/datatypes.c b/src/datatypes.c
index 88ad695..ad10f6b 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -287,7 +287,7 @@ virUnrefConnect(virConnectPtr conn) {
     int refs;

     if ((!VIR_IS_CONNECT(conn))) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
         return(-1);
     }
     virMutexLock(&conn->lock);
@@ -344,8 +344,16 @@ virDomainPtr
 virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
     virDomainPtr ret = NULL;

-    if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
+        return(NULL);
+    }
+    if (uuid == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
         return(NULL);
     }
     virMutexLock(&conn->lock);
@@ -455,7 +463,7 @@ virUnrefDomain(virDomainPtr domain) {
     int refs;

     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG, _("bad domain or no connection"));
         return(-1);
     }
     virMutexLock(&domain->conn->lock);
@@ -489,8 +497,16 @@ virNetworkPtr
 virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
     virNetworkPtr ret = NULL;

-    if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
+        return(NULL);
+    }
+    if (uuid == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
         return(NULL);
     }
     virMutexLock(&conn->lock);
@@ -592,7 +608,8 @@ virUnrefNetwork(virNetworkPtr network) {
     int refs;

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG,
+                        _("bad network or no connection"));
         return(-1);
     }
     virMutexLock(&network->conn->lock);
@@ -628,8 +645,12 @@ virInterfacePtr
 virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
     virInterfacePtr ret = NULL;

-    if ((!VIR_IS_CONNECT(conn)) || (name == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
         return(NULL);
     }

@@ -774,7 +795,8 @@ virUnrefInterface(virInterfacePtr iface) {
     int refs;

     if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG,
+                        _("bad interface or no connection"));
         return(-1);
     }
     virMutexLock(&iface->conn->lock);
@@ -806,11 +828,20 @@ virUnrefInterface(virInterfacePtr iface) {
  * Returns a pointer to the network, or NULL in case of failure
  */
 virStoragePoolPtr
-virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uuid) {
+virGetStoragePool(virConnectPtr conn, const char *name,
+                  const unsigned char *uuid) {
     virStoragePoolPtr ret = NULL;

-    if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
+        return(NULL);
+    }
+    if (uuid == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
         return(NULL);
     }
     virMutexLock(&conn->lock);
@@ -913,7 +944,8 @@ virUnrefStoragePool(virStoragePoolPtr pool) {
     int refs;

     if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG,
+                        _("bad storage pool or no connection"));
         return(-1);
     }
     virMutexLock(&pool->conn->lock);
@@ -946,11 +978,20 @@ virUnrefStoragePool(virStoragePoolPtr pool) {
  * Returns a pointer to the storage vol, or NULL in case of failure
  */
 virStorageVolPtr
-virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const char *key) {
+virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
+                 const char *key) {
     virStorageVolPtr ret = NULL;

-    if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (key == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
+        return(NULL);
+    }
+    if (key == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing key"));
         return(NULL);
     }
     virMutexLock(&conn->lock);
@@ -1062,7 +1103,8 @@ virUnrefStorageVol(virStorageVolPtr vol) {
     int refs;

     if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG,
+                        _("bad storage volume or no connection"));
         return(-1);
     }
     virMutexLock(&vol->conn->lock);
@@ -1097,8 +1139,12 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
 {
     virNodeDevicePtr ret = NULL;

-    if ((!VIR_IS_CONNECT(conn)) || (name == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
         return(NULL);
     }
     virMutexLock(&conn->lock);
@@ -1229,9 +1275,17 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid,
     virSecretPtr ret = NULL;
     char uuidstr[VIR_UUID_STRING_BUFLEN];

-    if (!VIR_IS_CONNECT(conn) || uuid == NULL || usageID == NULL) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (uuid == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
+        return(NULL);
+    }
+    if (usageID == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing usageID"));
+        return(NULL);
     }
     virMutexLock(&conn->lock);

@@ -1329,7 +1383,7 @@ virUnrefSecret(virSecretPtr secret) {
     int refs;

     if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG, _("bad secret or no connection"));
         return -1;
     }
     virMutexLock(&secret->conn->lock);
@@ -1422,8 +1476,16 @@ virNWFilterPtr
 virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid) {
     virNWFilterPtr ret = NULL;

-    if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
+        return(NULL);
+    }
+    if (uuid == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
         return(NULL);
     }
     virMutexLock(&conn->lock);
@@ -1526,7 +1588,8 @@ virUnrefNWFilter(virNWFilterPtr pool) {
     int refs;

     if (!VIR_IS_CONNECTED_NWFILTER(pool)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG,
+                        _("bad nwfilter or no connection"));
         return -1;
     }
     virMutexLock(&pool->conn->lock);
@@ -1549,8 +1612,12 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
 {
     virDomainSnapshotPtr ret = NULL;

-    if ((!VIR_IS_DOMAIN(domain)) || (name == NULL)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!VIR_IS_DOMAIN(domain)) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("bad domain"));
+        return(NULL);
+    }
+    if (name == NULL) {
+        virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
         return(NULL);
     }
     virMutexLock(&domain->conn->lock);
@@ -1630,7 +1697,7 @@ virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot)
     int refs;

     if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) {
-        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibConnError(VIR_ERR_INVALID_ARG, _("not a snapshot"));
         return(-1);
     }

-- 
1.7.0.1


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