[libvirt] [PATCH] nwfilter: variable 'obj' must be initialized inside nwfilterBindingCreateXML().

Julio Faracco posted 1 patch 5 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20180627024753.15761-1-jcfaracco@gmail.com
Test syntax-check passed
src/nwfilter/nwfilter_driver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[libvirt] [PATCH] nwfilter: variable 'obj' must be initialized inside nwfilterBindingCreateXML().
Posted by Julio Faracco 5 years, 10 months ago
The function nwfilterBindingCreateXML() is failing to compile due to a
conditional branch which leads to a undefined 'obj' variable. So 'obj'
must have a initial value to avoid compilation errors. See the problem:

  CC       nwfilter/libvirt_driver_nwfilter_impl_la-nwfilter_driver.lo
nwfilter/nwfilter_driver.c:752:9: error: variable 'obj' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
    if (virNWFilterBindingCreateXMLEnsureACL(conn, def) < 0)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nwfilter/nwfilter_driver.c:779:10: note: uninitialized use occurs here
    if (!obj)
         ^~~
nwfilter/nwfilter_driver.c:752:5: note: remove the 'if' if its condition is always false
    if (virNWFilterBindingCreateXMLEnsureACL(conn, def) < 0)
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nwfilter/nwfilter_driver.c:742:33: note: initialize the variable 'obj' to silence this warning
    virNWFilterBindingObjPtr obj;
                                ^
                                 = NULL

This commit initialized 'obj' with NULL to fix the error properly.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 src/nwfilter/nwfilter_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index d385b46f5f..ed34586105 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -739,8 +739,8 @@ nwfilterBindingCreateXML(virConnectPtr conn,
                          const char *xml,
                          unsigned int flags)
 {
-    virNWFilterBindingObjPtr obj;
     virNWFilterBindingDefPtr def;
+    virNWFilterBindingObjPtr obj = NULL;
     virNWFilterBindingPtr ret = NULL;
 
     virCheckFlags(0, NULL);
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] nwfilter: variable 'obj' must be initialized inside nwfilterBindingCreateXML().
Posted by Pavel Hrdina 5 years, 10 months ago
On Tue, Jun 26, 2018 at 11:47:53PM -0300, Julio Faracco wrote:
> The function nwfilterBindingCreateXML() is failing to compile due to a
> conditional branch which leads to a undefined 'obj' variable. So 'obj'
> must have a initial value to avoid compilation errors. See the problem:
> 
>   CC       nwfilter/libvirt_driver_nwfilter_impl_la-nwfilter_driver.lo
> nwfilter/nwfilter_driver.c:752:9: error: variable 'obj' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>     if (virNWFilterBindingCreateXMLEnsureACL(conn, def) < 0)
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> nwfilter/nwfilter_driver.c:779:10: note: uninitialized use occurs here
>     if (!obj)
>          ^~~
> nwfilter/nwfilter_driver.c:752:5: note: remove the 'if' if its condition is always false
>     if (virNWFilterBindingCreateXMLEnsureACL(conn, def) < 0)
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> nwfilter/nwfilter_driver.c:742:33: note: initialize the variable 'obj' to silence this warning
>     virNWFilterBindingObjPtr obj;
>                                 ^
>                                  = NULL
> 
> This commit initialized 'obj' with NULL to fix the error properly.
> 
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  src/nwfilter/nwfilter_driver.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Pushed now, thanks.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list