Patchwork libbacktrace patch committed: Always clear union in read_attribute

login
register
mail settings
Submitter Ian Taylor
Date Nov. 20, 2012, 5:28 p.m.
Message ID <mcrehjoxjyu.fsf@google.com>
Download mbox | patch
Permalink /patch/200488/
State New
Headers show

Comments

Ian Taylor - Nov. 20, 2012, 5:28 p.m.
http://gcc.gnu.org/ml/gcc-regression/2012-11/msg00279.html points out a
may-be-used-uninitialized warning, turned into an error, when building
libbacktrace.  The warning is incorrect: the value is initialized.  The
warning will no longer turn into an error.  But it is easy enough to
force an initialization to avoid the warning.  That is what this patch
does.  Bootstrapped and ran libbacktrace testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian


2012-11-20  Ian Lance Taylor  <iant@google.com>

	* dwarf.c (read_attribute): Always clear val.

Patch

Index: dwarf.c
===================================================================
--- dwarf.c	(revision 193484)
+++ dwarf.c	(working copy)
@@ -654,6 +654,12 @@  read_attribute (enum dwarf_form form, st
 		const unsigned char *dwarf_str, size_t dwarf_str_size,
 		struct attr_val *val)
 {
+  /* Avoid warnings about val.u.FIELD may be used uninitialized if
+     this function is inlined.  The warnings aren't valid but can
+     occur because the different fields are set and used
+     conditionally.  */
+  memset (val, 0, sizeof *val);
+
   switch (form)
     {
     case DW_FORM_addr: