Skip to contentSkip to conversation

xen-mapcache: Fix a build error with -fexceptions

PATCH In review Alex Brett 2 participants 3 messages Nov 24

lore
Share & tools
lore

Alex Brett

author
#0 lore raw

PATCH 1/1 xen-mapcache: Fix a build error with -fexceptions

When building with -Werror=maybe-uninitialized and -fexceptions, gcc can report:
error: 'err' may be used uninitialized [-Werror=maybe-uninitialized]

err gets assigned to g_new0() unconditionally, but under -fexceptions the calls to trace_xen_remap_bucket() or g_new0() might unwind, leading the g_autofree cleanup to run g_free() on an uninitialised err. Avoid the warning and any future issues by initialising it to NULL in the same pattern as other definitions.

---
 hw/xen/xen-mapcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen-mapcache.c +1 -1
index e30c07c2ee..0a19cfdc1b 100644
@@ -199,7 +199,7 @@ static void xen_remap_bucket(MapCache *mc,
     uint8_t *vaddr_base;
     g_autofree uint32_t *refs = NULL;
     g_autofree xen_pfn_t *pfns = NULL;
-    g_autofree int *err;
+    g_autofree int *err = NULL;
     unsigned int i;
     hwaddr nb_pfn = size >> XC_PAGE_SHIFT;
 
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Alex Brett via qemu development

When building with -Werror=maybe-uninitialized and -fexceptions, gcc can report:
error: 'err' may be used uninitialized [-Werror=maybe-uninitialized]

err gets assigned to g_new0() unconditionally, but under -fexceptions the calls to trace_xen_remap_bucket() or g_new0() might unwind, leading the g_autofree cleanup to run g_free() on an uninitialised err. Avoid the warning and any future issues by initialising it to NULL in the same pattern as other definitions.

---
 hw/xen/xen-mapcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen-mapcache.c +0 -0
index e30c07c2ee..0a19cfdc1b 100644

hw/xen/xen-mapcache.c static void xen_remap_bucket(MapCache *mc, · line 204

Quoted 7 lines
hw/xen/xen-mapcache.c +1 -1
@@ -199,7 +199,7 @@ static void xen_remap_bucket(MapCache *mc,
     uint8_t *vaddr_base;
     g_autofree uint32_t *refs = NULL;
     g_autofree xen_pfn_t *pfns = NULL;
-    g_autofree int *err;
+    g_autofree int *err = NULL;
     unsigned int i;
     hwaddr nb_pfn = size >> XC_PAGE_SHIFT;

Explicit init of a g_autofree pointer is the recommended pattern, so

but why are you building with "-fexceptions" ? Trying to throw a C++ exception through QEMU's C code seems like it's likely to run into all kinds of problems and corner cases...

thanks
-- PMM