xen-mapcache: Fix a build error with -fexceptions
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
@@ -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
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 totrace_xen_remap_bucket()org_new0()might unwind, leading theg_autofreecleanup to rung_free()on an uninitialised err. Avoid the warning and any future issues by initialising it to NULL in the same pattern as other definitions.Signed-off-by Alex Brett <[email protected]>--- hw/xen/xen-mapcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/xen/xen-mapcache.c +0
-0
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
Quoted 3 lines
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...
So "-fexceptions" is a default compiler flag for Fedora and derived distributions - their justification is in the "Individual compiler flags" section of
https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/rawhide/f/buildflags.md
Alex