[libvirt] [PATCH v2 06/21] conf: Improve error handling in virDomainChrDefFormat()

Andrea Bolognani posted 21 patches 8 years, 2 months ago
There is a newer version of this series
[libvirt] [PATCH v2 06/21] conf: Improve error handling in virDomainChrDefFormat()
Posted by Andrea Bolognani 8 years, 2 months ago
We don't need to store the return value since we never modify it; we
should also report failure when virDomainChrSourceDefFormat() fails.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 src/conf/domain_conf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 224b88d9a..cb4ed6ef6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -24025,8 +24025,6 @@ virDomainChrDefFormat(virBufferPtr buf,
     const char *elementName = virDomainChrDeviceTypeToString(def->deviceType);
     bool tty_compat;
 
-    int ret = 0;
-
     if (!elementName) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected char device type %d"),
@@ -24044,7 +24042,9 @@ virDomainChrDefFormat(virBufferPtr buf,
     if (virDomainChrAttrsDefFormat(buf, def->source, tty_compat) < 0)
         return -1;
     virBufferAddLit(buf, ">\n");
-    virDomainChrSourceDefFormat(buf, def->source, flags);
+
+    if (virDomainChrSourceDefFormat(buf, def->source, flags) < 0)
+       return -1;
 
     if (virDomainChrTargetDefFormat(buf, def, flags) < 0)
        return -1;
@@ -24054,7 +24054,7 @@ virDomainChrDefFormat(virBufferPtr buf,
     virBufferAdjustIndent(buf, -2);
     virBufferAsprintf(buf, "</%s>\n", elementName);
 
-    return ret;
+    return 0;
 }
 
 static int
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 06/21] conf: Improve error handling in virDomainChrDefFormat()
Posted by Pavel Hrdina 8 years, 2 months ago
On Tue, Nov 21, 2017 at 05:42:16PM +0100, Andrea Bolognani wrote:
> We don't need to store the return value since we never modify it; we
> should also report failure when virDomainChrSourceDefFormat() fails.
> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>  src/conf/domain_conf.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 224b88d9a..cb4ed6ef6 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -24025,8 +24025,6 @@ virDomainChrDefFormat(virBufferPtr buf,
>      const char *elementName = virDomainChrDeviceTypeToString(def->deviceType);
>      bool tty_compat;
>  
> -    int ret = 0;
> -
>      if (!elementName) {
>          virReportError(VIR_ERR_INTERNAL_ERROR,
>                         _("unexpected char device type %d"),
> @@ -24044,7 +24042,9 @@ virDomainChrDefFormat(virBufferPtr buf,
>      if (virDomainChrAttrsDefFormat(buf, def->source, tty_compat) < 0)
>          return -1;
>      virBufferAddLit(buf, ">\n");
> -    virDomainChrSourceDefFormat(buf, def->source, flags);
> +
> +    if (virDomainChrSourceDefFormat(buf, def->source, flags) < 0)
> +       return -1;

This change could be separated and all other calls of that function
should be checked for error since none of them are checked.

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