[libvirt] [PATCH v2 11/29] conf: Avoid temporary variable in virDomainDiskBackingStoreFormat

Peter Krempa posted 29 patches 6 years, 10 months ago
[libvirt] [PATCH v2 11/29] conf: Avoid temporary variable in virDomainDiskBackingStoreFormat
Posted by Peter Krempa 6 years, 10 months ago
Modify the check that the format is in range to be standalone and use
the convertor function directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/domain_conf.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fa4454a6ca..5adca7c29c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23826,7 +23826,6 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
                                 virDomainXMLOptionPtr xmlopt,
                                 unsigned int flags)
 {
-    const char *format;
     bool inactive = flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE;

     if (!backingStore)
@@ -23841,8 +23840,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
         return 0;
     }

-    if (backingStore->format <= 0 ||
-        !(format = virStorageFileFormatTypeToString(backingStore->format))) {
+    if (backingStore->format <= 0 || backingStore->format >= VIR_STORAGE_FILE_LAST) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected disk backing store format %d"),
                        backingStore->format);
@@ -23856,7 +23854,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
     virBufferAddLit(buf, ">\n");
     virBufferAdjustIndent(buf, 2);

-    virBufferAsprintf(buf, "<format type='%s'/>\n", format);
+    virBufferAsprintf(buf, "<format type='%s'/>\n",
+                      virStorageFileFormatTypeToString(backingStore->format));
     if (virDomainDiskSourceFormat(buf, backingStore, 0, false, flags, xmlopt) < 0 ||
         virDomainDiskBackingStoreFormat(buf, backingStore->backingStore,
                                         xmlopt, flags) < 0)
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 11/29] conf: Avoid temporary variable in virDomainDiskBackingStoreFormat
Posted by Ján Tomko 6 years, 10 months ago
On Fri, Mar 22, 2019 at 07:00:47PM +0100, Peter Krempa wrote:
>Modify the check that the format is in range to be standalone and use
>the convertor function directly.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/conf/domain_conf.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

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