From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: Errors in compilation // xl_cmdimpl.c:2733:11 ... Date: Fri, 24 Aug 2012 20:23:47 +0100 Message-ID: <5037D4C3.4060309@citrix.com> References: <20120824164301.46800@gmx.net> <5037CB11.9000308@citrix.com> <1345835562.4847.3.camel@dagon.hellion.org.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050605020601030102020804" Return-path: In-Reply-To: <1345835562.4847.3.camel@dagon.hellion.org.uk> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: "p.d@gmx.de" , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org --------------050605020601030102020804 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 24/08/12 20:12, Ian Campbell wrote: > On Fri, 2012-08-24 at 19:42 +0100, Andrew Cooper wrote: >> On 24/08/12 17:43, p.d@gmx.de wrote: >>> nice time, >>> >>> Ian, I'm not sure, but I think after Your patch: >>> http://xenbits.xen.org/hg/xen-unstable.hg/rev/4ca40e0559c3 >>> >>> xen-tools (+qemu+seabios) will not be maked :) >>> >>> Here are last lines of "make -j7": >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>> gcc -O1 -fno-omit-frame-pointer -m64 -g -fno-strict-aliasing -std=3D= gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused= -but-set-variable -D__XEN_TOOLS__ -MMD -MF ._libxl_save_msgs_callout.o.= d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fno-optimize-sibling-calls = -Werror -Wno-format-zero-length -Wmissing-declarations -Wno-declaration-= after-statement -Wformat-nonliteral -I. -fPIC -pthread -I/usr/src/xen_201= 2_08_24_rev_25779/tools/libxl/../../tools/libxc -I/usr/src/xen_2012_08_24= _rev_25779/tools/libxl/../../tools/include -I/usr/src/xen_2012_08_24_rev_= 25779/tools/libxl/../../tools/libxc -I/usr/src/xen_2012_08_24_rev_25779/t= ools/libxl/../../tools/include -I/usr/src/xen_2012_08_24_rev_25779/tools/= libxl/../../tools/xenstore -I/usr/src/xen_2012_08_24_rev_25779/tools/libx= l/../../tools/include -I/usr/src/xen_2012_08_24_rev_25779/tools/libxl/../= =2E./tools/blktap2/control -I/usr/src/xen_2012_08_24_rev_25779/tools/libx= l/../../tools/blktap2/include -I/usr/src/xen_2012_08_24_rev_25779/tools/l= ibxl/../../tools/include -include /usr/src/xen_2012_08_24_rev_25779/tools= /libxl/../../tools/config.h -c -o _libxl_save_msgs_callout.o _libxl_save= _msgs_callout.c=20 >>> xl_cmdimpl.c: In function =E2=80=98main_list=E2=80=99: >>> xl_cmdimpl.c:2733:11: error: =E2=80=98hand=E2=80=99 may be used unini= tialized in this function [-Werror=3Duninitialized] >>> xl_cmdimpl.c:2689:14: note: =E2=80=98hand=E2=80=99 was declared here >>> >> Please try the attached patch. I have fixed the error, and also >> future-proofed the logic. >> >> @Ian: the patch can be slimed down if default_output_format can be >> guaranteed not to change across the duration of this function call, bu= t >> my cursory glance at this otherwise-unfamilar codebase cant say for ce= rtain. > It can only change during argument parsing. > > gcc is being a bit dumb here since default_output_format is a staticall= y > initialised enum whose only values are OUTPUT_FORMAT_JSON and > OUTPUT_FORMAT_SXP. > > I suspect that now you have re-written it so that hand is only touched > iff format =3D=3D JSON and format is const that initialisation of hand = is no > longer necessary. But nonetheless: > Acked-by: Ian Campbell > > Ian. > Sadly, hand being touched iff format =3D=3D JSON was still not enough to satisfy my version of GCC. Attached is a far slimmed version which explicitly sets hand to NULL at the top, and future-proofs the use of hand in the middle of the domain lo= op. --=20 Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer T: +44 (0)1223 225 900, http://www.citrix.com --------------050605020601030102020804 Content-Type: text/x-patch; name="fix-cmdimpl-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-cmdimpl-v2.patch" # HG changeset patch # Parent 4ca40e0559c33205fb5163b10249a0fd5fda39b9 tools/xl: Fix uninitialized variable error. c/s 25779:4ca40e0559c3 introduced a compilation error for any build system using -Werror=uninitialized, such as the default CentOS 5.7 version of gcc. And with good reason, because if the global libxl default_output_format is neither OUTPUT_FORMAT_SXP nor OUTPUT_FORMAT_JSON, the variable hand will be used before being initialised. The attached patch fixes the warning, and futher fixes the logic to work correctly when a new OUTPUT_FORMAT is added to xl. Signed-off-by: Andrew Cooper diff -r 4ca40e0559c3 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2686,7 +2686,7 @@ static void list_domains_details(const l uint8_t *data; int i, len, rc; - yajl_gen hand; + yajl_gen hand = NULL; yajl_gen_status s; const char *buf; libxl_yajl_length yajl_len = 0; @@ -2714,10 +2714,10 @@ static void list_domains_details(const l CHK_ERRNO(asprintf(&config_source, "", info[i].domid)); libxl_domain_config_init(&d_config); parse_config_data(config_source, (char *)data, len, &d_config, NULL); - if (default_output_format == OUTPUT_FORMAT_SXP) + if (default_output_format == OUTPUT_FORMAT_JSON) + s = printf_info_one_json(hand, info[i].domid, &d_config); + else printf_info_sexp(domid, &d_config); - else - s = printf_info_one_json(hand, info[i].domid, &d_config); libxl_domain_config_dispose(&d_config); free(data); free(config_source); --------------050605020601030102020804 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --------------050605020601030102020804--