[libvirt] [libvirt-glib] Use gvir_error_set_literal in more places

Christophe Fergeau cfergeau at redhat.com
Mon Dec 5 16:14:10 UTC 2011


GVirConnection has some gvir_set_error uses that can be replaced
by gvir_set_error_set_literal. When passing a single string, this is
safer since we are guaranteed that unwanted printf-format sequences
in the string won't cause issues.
---
 libvirt-gobject/libvirt-gobject-connection.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 50cd860..f478948 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -421,9 +421,9 @@ gboolean gvir_connection_open(GVirConnection *conn,
     if (!priv->uri) {
         char *uri = virConnectGetURI(priv->conn);
         if (!uri) {
-            gvir_set_error(err, GVIR_CONNECTION_ERROR,
+            gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                            0,
-                           "%s", "Unable to get connection URI");
+                           "Unable to get connection URI");
             virConnectClose(priv->conn);
             priv->conn = NULL;
             g_mutex_unlock(priv->lock);
@@ -618,9 +618,9 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
 
     g_mutex_lock(priv->lock);
     if (!priv->conn) {
-        g_set_error(err, GVIR_CONNECTION_ERROR,
-                    0,
-                    "Connection is not open");
+        g_set_error_literal(err, GVIR_CONNECTION_ERROR,
+                            0,
+                            "Connection is not open");
         g_mutex_unlock(priv->lock);
         goto cleanup;
     }
@@ -633,9 +633,9 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
         goto cleanup;
 
     if ((nactive = virConnectNumOfDomains(vconn)) < 0) {
-        gvir_set_error(err, GVIR_CONNECTION_ERROR,
-                       0,
-                       "Unable to count domains");
+        gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
+                               0,
+                               "Unable to count domains");
         goto cleanup;
     }
     if (nactive) {
@@ -644,9 +644,9 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
 
         active = g_new(gint, nactive);
         if ((nactive = virConnectListDomains(vconn, active, nactive)) < 0) {
-            gvir_set_error(err, GVIR_CONNECTION_ERROR,
-                           0,
-                           "Unable to list domains");
+            gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
+                                   0,
+                                   "Unable to list domains");
             goto cleanup;
         }
     }
-- 
1.7.7.3




More information about the libvir-list mailing list