Pino Toscano
2018-May-04 13:55 UTC
[Libguestfs] [PATCH] appliance: initialize the appliance_files struct
Some compilers do not manage to figure out that the members of it are set only when search_appliance() in the end returns 1, which is already checked. Help them a bit by resetting the appliance_files struct on our own, so they will not report that 'appliance.kernel', and the others are used as uninitialized. --- lib/appliance.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/appliance.c b/lib/appliance.c index 360d4105f..0fa37339e 100644 --- a/lib/appliance.c +++ b/lib/appliance.c @@ -118,6 +118,8 @@ guestfs_int_build_appliance (guestfs_h *g, struct appliance_files appliance; + memset (&appliance, 0, sizeof appliance); + if (search_appliance (g, &appliance) != 1) return -1; -- 2.14.3
Richard W.M. Jones
2018-May-04 14:10 UTC
Re: [Libguestfs] [PATCH] appliance: initialize the appliance_files struct
On Fri, May 04, 2018 at 03:55:35PM +0200, Pino Toscano wrote:> Some compilers do not manage to figure out that the members of it are > set only when search_appliance() in the end returns 1, which is already > checked. Help them a bit by resetting the appliance_files struct on our > own, so they will not report that 'appliance.kernel', and the others are > used as uninitialized. > --- > lib/appliance.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/lib/appliance.c b/lib/appliance.c > index 360d4105f..0fa37339e 100644 > --- a/lib/appliance.c > +++ b/lib/appliance.c > @@ -118,6 +118,8 @@ guestfs_int_build_appliance (guestfs_h *g, > > struct appliance_files appliance; > > + memset (&appliance, 0, sizeof appliance); > + > if (search_appliance (g, &appliance) != 1) > return -1; >ACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Eric Blake
2018-May-04 14:31 UTC
Re: [Libguestfs] [PATCH] appliance: initialize the appliance_files struct
On 05/04/2018 08:55 AM, Pino Toscano wrote:> Some compilers do not manage to figure out that the members of it are > set only when search_appliance() in the end returns 1, which is already > checked. Help them a bit by resetting the appliance_files struct on our > own, so they will not report that 'appliance.kernel', and the others are > used as uninitialized. > --- > lib/appliance.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/lib/appliance.c b/lib/appliance.c > index 360d4105f..0fa37339e 100644 > --- a/lib/appliance.c > +++ b/lib/appliance.c > @@ -118,6 +118,8 @@ guestfs_int_build_appliance (guestfs_h *g, > > struct appliance_files appliance; > > + memset (&appliance, 0, sizeof appliance); > +It's semantically identical but shorter to write: struct appliance_files appliance = { 0 }; Up to you if you like that. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Maybe Matching Threads
- Re: [PATCH v1 1/2] appliance: search all types of appliances for each path separately
- Re: [PATCH v2 1/2] appliance: search all types of appliances for each path separately
- [PATCH 0/2] lib: appliance: qemu 2.9.0 supports TCG with -cpu host on x86 (RHBZ#1277744).
- [PATCH] appliance: touch /etc/fstab when enabling the network (RHBZ#1224795)
- [PATCH v2 0/4] daemon: Translate device names if Linux device is unstable (RHBZ#1804207).