test qgraph.c: Fix segs due to out of scope default
PATCH 1/1 test qgraph.c: Fix segs due to out of scope default
From: "Dr. David Alan Gilbert" <[email protected]>
The test uses the trick:
if (!opts) {
opts = &(QOSGraph...Options) { };}
in a couple of places, however the temporary created
by the &() {} goes out of scope at the bottom of the if, and results in a seg or assert when opts-> fields are used (on fedora 30's gcc 9).
--- tests/libqos/qgraph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tests/libqos/qgraph.c +4 -2
@@ -77,6 +77,7 @@ static void add_edge(const char *source, const char *dest, {char *key;QOSGraphEdgeList *list =g_hash_table_lookup (edge_table, source); +QOSGraphEdgeOptions def_opts = { };if (!list) { list =g_new0 (QOSGraphEdgeList,1 );
@@ -85,7 +86,7 @@ static void add_edge(const char *source, const char *dest, }if (!opts) { - opts = &(QOSGraphEdgeOptions ) { }; + opts = &def_opts; }QOSGraphEdge *edge =g_new0 (QOSGraphEdge,1 );
@@ -590,9 +591,10 @@ void qos_add_test(const char *name, const char *interface, {QOSGraphNode *node;char *test_name =g_strdup_printf ("%s-tests/%s" , interface, name);; +QOSGraphTestOptions def_opts = { };if (!opts) { - opts = &(QOSGraphTestOptions ) { }; + opts = &def_opts; } node =create_node (test_name,QNODE_TEST ); node->u.test.function = test_func;
Signature · 1 line
2.21.0
Quoted 12 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
The test uses the trick:
if (!opts) { opts = &(QOSGraph...Options) { }; }in a couple of places, however the temporary created
by the &() {} goes out of scope at the bottom of the if, and results in a seg or assert when opts-> fields are used (on fedora 30's gcc 9).
Quoted 5 lines
Fixes fc281c802022cb3a73a5Signed-off-by Dr. David Alan Gilbert <[email protected]>--- tests/libqos/qgraph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Fixing it for 4.0 would be nice (we can't promise that everything in 4.0 is clean for gcc 9, but as long as we have to do -rc3 anyways, fixing undefined behavior into something well-defined like this seems reasonable)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 7 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
The test uses the trick:
if (!opts) { opts = &(QOSGraph...Options) { }; }
Quoted 7 lines
in a couple of places, however the temporary created
by the &() {} goes out of scope at the bottom of the if, and results in a seg or assert when opts-> fields are used (on fedora 30's gcc 9).Fixes fc281c802022cb3a73a5Signed-off-by Dr. David Alan Gilbert <[email protected]>
Thomas, can you pick this up?
Paolo
Quoted 38 lines
--- tests/libqos/qgraph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tests/libqos/qgraph.c +4
-2@@ -77,6 +77,7 @@ static void add_edge(const char *source, const char *dest, {char *key;QOSGraphEdgeList *list =g_hash_table_lookup (edge_table, source); +QOSGraphEdgeOptions def_opts = { };if (!list) { list =g_new0 (QOSGraphEdgeList,1 );@@ -85,7 +86,7 @@ static void add_edge(const char *source, const char *dest, }if (!opts) { - opts = &(QOSGraphEdgeOptions ) { }; + opts = &def_opts; }QOSGraphEdge *edge =g_new0 (QOSGraphEdge,1 );@@ -590,9 +591,10 @@ void qos_add_test(const char *name, const char *interface, {QOSGraphNode *node;char *test_name =g_strdup_printf ("%s-tests/%s" , interface, name);; +QOSGraphTestOptions def_opts = { };if (!opts) { - opts = &(QOSGraphTestOptions ) { }; + opts = &def_opts; } node =create_node (test_name,QNODE_TEST ); node->u.test.function = test_func;
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
The test uses the trick:
if (!opts) { opts = &(QOSGraph...Options) { }; }in a couple of places, however the temporary created
by the &() {} goes out of scope at the bottom of the if, and results in a seg or assert when opts-> fields are used (on fedora 30's gcc 9).
Quoted 4 lines
Quoted 2 lines
Fixes fc281c802022cb3a73a5Signed-off-by Dr. David Alan Gilbert <[email protected]>Thomas, can you pick this up?
Sure, queued it to my qtest-next branch now:
https://gitlab.com/huth/qemu/tree/qtest-next
I'll send a PULL request on Monday.
Thomas