This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

(apparently harmless) little bug in cp/init.c


Hi all,

I was showing valgrind to some coworkers, and when run on top-of-tree
cc1plus it immediately claimed there was a conditional dependant
on an uninitialized value, over in cp/init.c::sort_member_init().

sort_member_init has a local variable, 'uses_unions_p'; it passes
a reference to that var to cp/init.c::build_field_list() where it
is set to '1' if there is a UNION_TYPE in the tree or something
like that.  But it is never set to '0' if there are no UNION_TYPEs,
so the conditional later in sort_member_init(),

  /* [class.base.init]

     If a ctor-initializer specifies more than one mem-initializer for 
     multiple members of the same union (including members of
     anonymous unions), the ctor-initializer is ill-formed.  */
  if (uses_unions_p)
    {       

can depend on random stack-goobers.

uses_unions_p could be initialized when declared in sort_member_init(),
but it seems to me that build_field_list() should set it to zero
or one, not just one, so that's the patch I've included below.

ObPraiseValgrind - valgrind rules.  http://developer.kde.org/~sewardj/

Jason

2002-09-09  Jason Molenda  (jmolenda@apple.com)

        * init.c (build_field_list): Provide uses_unions_p with a default value.

Index: init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.290
diff -u -p -r1.290 init.c
--- init.c	9 Aug 2002 01:16:39 -0000	1.290
+++ init.c	9 Sep 2002 19:58:18 -0000
@@ -328,6 +328,8 @@ build_field_list (t, list, uses_unions_p
 {
   tree fields;
 
+  *uses_unions_p = 0;
+
   /* Note whether or not T is a union.  */
   if (TREE_CODE (t) == UNION_TYPE)
     *uses_unions_p = 1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]