[libvirt] [libvirt PATCH v6 02/15] xen_common: Change xenConfigGetUUID to using virConfGetValueString

Fabiano Fidêncio posted 15 patches 7 years, 4 months ago
[libvirt] [libvirt PATCH v6 02/15] xen_common: Change xenConfigGetUUID to using virConfGetValueString
Posted by Fabiano Fidêncio 7 years, 4 months ago
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
---
 src/xenconfig/xen_common.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index a35e1aff58..08fbfff44f 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -183,7 +183,7 @@ xenConfigCopyStringOpt(virConfPtr conf, const char *name, char **value)
 static int
 xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid)
 {
-    virConfValuePtr val;
+    char *string = NULL;
 
     if (!uuid || !name || !conf) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -191,7 +191,7 @@ xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid)
         return -1;
     }
 
-    if (!(val = virConfGetValue(conf, name))) {
+    if (virConfGetValueString(conf, name, &string) <= 0) {
         if (virUUIDGenerate(uuid) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("Failed to generate UUID"));
@@ -201,24 +201,20 @@ xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid)
         }
     }
 
-    if (val->type != VIR_CONF_STRING) {
-        virReportError(VIR_ERR_CONF_SYNTAX,
-                       _("config value %s not a string"), name);
-        return -1;
-    }
-
-    if (!val->str) {
+    if (!string) {
         virReportError(VIR_ERR_CONF_SYNTAX,
                        _("%s can't be empty"), name);
         return -1;
     }
 
-    if (virUUIDParse(val->str, uuid) < 0) {
+    if (virUUIDParse(string, uuid) < 0) {
         virReportError(VIR_ERR_CONF_SYNTAX,
                        _("%s not parseable"), val->str);
+        VIR_FREE(string);
         return -1;
     }
 
+    VIR_FREE(string);
     return 0;
 }
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt PATCH v6 02/15] xen_common: Change xenConfigGetUUID to using virConfGetValueString
Posted by John Ferlan 7 years, 4 months ago

On 09/18/2018 02:48 PM, Fabiano Fidêncio wrote:
> Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
> ---
>  src/xenconfig/xen_common.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
> index a35e1aff58..08fbfff44f 100644
> --- a/src/xenconfig/xen_common.c
> +++ b/src/xenconfig/xen_common.c
> @@ -183,7 +183,7 @@ xenConfigCopyStringOpt(virConfPtr conf, const char *name, char **value)
>  static int
>  xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid)
>  {
> -    virConfValuePtr val;
> +    char *string = NULL;
>  
>      if (!uuid || !name || !conf) {
>          virReportError(VIR_ERR_INVALID_ARG, "%s",
> @@ -191,7 +191,7 @@ xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid)
>          return -1;
>      }
>  
> -    if (!(val = virConfGetValue(conf, name))) {

This is the "isn't found" or "was missing" test...

> +    if (virConfGetValueString(conf, name, &string) <= 0) {

But this takes it one step too far. If return < 0, then we had "if
(cval->type != VIR_CONF_STRING)" or "VIR_STRDUP" failure.

However, if you change to:

    int rc;
...
    if ((rc = virConfGetValueString(conf, name, &string)) < 0)
        return -1;

    if (rc == 0) {

then I believe we're good.

With the change,

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

[I can make the change locally, but I've forgotten the magic incantation
or rpm that allows the xen* files to be built on my host, so I'm flying
blind w/r/t proper syntax ;-)]

>          if (virUUIDGenerate(uuid) < 0) {
>              virReportError(VIR_ERR_INTERNAL_ERROR,
>                             "%s", _("Failed to generate UUID"));

[...]

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list