[libvirt] [PATCH] vbox: fix compilation error

clang complains about possibly uninitialized variable: vbox/vbox_snapshot_conf.c:1355:9: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!(xPathContext = xmlXPathNewContext(xml))) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ So init 'ret' with NULL. --- src/vbox/vbox_snapshot_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 4909665..9c78410 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -1336,7 +1336,7 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath, { int result = -1; size_t i = 0; - char **ret; + char **ret = NULL; xmlDocPtr xml = NULL; xmlXPathContextPtr xPathContext = NULL; xmlNodePtr *nodes = NULL; -- 1.9.0

On 06/10/2014 11:10 AM, Roman Bogorodskiy wrote:
clang complains about possibly uninitialized variable:
vbox/vbox_snapshot_conf.c:1355:9: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!(xPathContext = xmlXPathNewContext(xml))) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So init 'ret' with NULL. --- src/vbox/vbox_snapshot_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK; you can push this sort of fix under the trivial build-breaker rule.
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 4909665..9c78410 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -1336,7 +1336,7 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath, { int result = -1; size_t i = 0; - char **ret; + char **ret = NULL; xmlDocPtr xml = NULL; xmlXPathContextPtr xPathContext = NULL; xmlNodePtr *nodes = NULL;
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Eric Blake wrote:
On 06/10/2014 11:10 AM, Roman Bogorodskiy wrote:
clang complains about possibly uninitialized variable:
vbox/vbox_snapshot_conf.c:1355:9: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!(xPathContext = xmlXPathNewContext(xml))) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So init 'ret' with NULL. --- src/vbox/vbox_snapshot_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK; you can push this sort of fix under the trivial build-breaker rule.
Pushed, thanks! Roman Bogorodskiy

On 10.06.2014 19:10, Roman Bogorodskiy wrote:
clang complains about possibly uninitialized variable:
vbox/vbox_snapshot_conf.c:1355:9: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!(xPathContext = xmlXPathNewContext(xml))) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So init 'ret' with NULL.
Okay, I must admit clang has cool error reporting. But in fact, ret may be used uninitialized way before reaching this line - there are two places before where conditional jump is possible. But I guess compiler is not SA tool anyway, right? Michal

Michal Privoznik wrote:
On 10.06.2014 19:10, Roman Bogorodskiy wrote:
clang complains about possibly uninitialized variable:
vbox/vbox_snapshot_conf.c:1355:9: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!(xPathContext = xmlXPathNewContext(xml))) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So init 'ret' with NULL.
Okay, I must admit clang has cool error reporting. But in fact, ret may be used uninitialized way before reaching this line - there are two places before where conditional jump is possible. But I guess compiler is not SA tool anyway, right?
Actually, it reported these cases as well: https://dpaste.de/oDuE I just decided to mention the first one as the cause of all the errors here is the same. Roman Bogorodskiy
participants (3)
-
Eric Blake
-
Michal Privoznik
-
Roman Bogorodskiy