[PATCH] qemu_monitor_json: Use proper initializer in qemuMonitorJSONGetBlockInfo()

Michal Privoznik via Devel posted 1 patch 5 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/9551e54a907e4ba9d8bc761e05f1d3fb1eb23a68.1750768078.git.mprivozn@redhat.com
src/qemu/qemu_monitor_json.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] qemu_monitor_json: Use proper initializer in qemuMonitorJSONGetBlockInfo()
Posted by Michal Privoznik via Devel 5 months, 3 weeks ago
From: Michal Privoznik <mprivozn@redhat.com>

Inside of qemuMonitorJSONGetBlockInfo() there's a for loop in
which a variable of struct qemuDomainDiskInfo type is declared
and initialized as { false }. This works only because stdbool.h
declares 'false' as a macro, so preprocessor expands initializer
to proper form of { 0 }.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index a6fb2a2013..2de68d6518 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2206,7 +2206,7 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon,
     for (i = 0; i < virJSONValueArraySize(devices); i++) {
         virJSONValue *dev;
         virJSONValue *image;
-        struct qemuDomainDiskInfo info = { false };
+        struct qemuDomainDiskInfo info = { 0 };
         const char *thisdev;
         const char *status;
         const char *qdev;
-- 
2.49.0
Re: [PATCH] qemu_monitor_json: Use proper initializer in qemuMonitorJSONGetBlockInfo()
Posted by Peter Krempa via Devel 5 months, 3 weeks ago
On Tue, Jun 24, 2025 at 14:27:58 +0200, Michal Privoznik via Devel wrote:
> From: Michal Privoznik <mprivozn@redhat.com>
> 
> Inside of qemuMonitorJSONGetBlockInfo() there's a for loop in
> which a variable of struct qemuDomainDiskInfo type is declared
> and initialized as { false }. This works only because stdbool.h
> declares 'false' as a macro, so preprocessor expands initializer
> to proper form of { 0 }.

Could you please elaborate what's wrong here?

The struct is declared as:

struct qemuDomainDiskInfo {
    bool removable;
    bool tray;
    bool tray_open;
    bool empty;
    int io_status;
    char *nodename;
};

> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_monitor_json.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index a6fb2a2013..2de68d6518 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -2206,7 +2206,7 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon,
>      for (i = 0; i < virJSONValueArraySize(devices); i++) {
>          virJSONValue *dev;
>          virJSONValue *image;
> -        struct qemuDomainDiskInfo info = { false };

Thus this defines 'info' as 'struct qemuDomainDiskInfo' and initializes
the 'removable' (first member) to 'false'. The rest is then
empty-initialized.

> +        struct qemuDomainDiskInfo info = { 0 };
>          const char *thisdev;
>          const char *status;
>          const char *qdev;
> -- 
> 2.49.0
>