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]

C++ PATCH: Avoid wild reads



Jeffrey Oldham figured out that we were touching uninitialized memory
in instantiate_template:

  for (clone = TREE_CHAIN (gen_tmpl);
       clone && DECL_CLONED_FUNCTION_P (clone);
       clone = TREE_CHAIN (clone))

Here, the clone can be something like a VAR_DECL that doesn't have a
full lang_decl, and therefore DECL_CLONED_FUNCTION_P doesn't make
sense.

Obvious fix attached, tested on i686-pc-linux-gnu.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2001-01-10  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (DECL_CLONED_FUNCTION_P): Avoid wild reads by not
	looking at DECL_CLONED_FUNCTION for non-functions.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.560
diff -c -p -r1.560 cp-tree.h
*** cp-tree.h	2001/01/10 10:57:17	1.560
--- cp-tree.h	2001/01/10 19:07:27
*************** struct lang_decl
*** 1959,1965 ****
  /* Nonzero if NODE (a FUNCTION_DECL) is a cloned constructor or
     destructor.  */
  #define DECL_CLONED_FUNCTION_P(NODE)		\
!   (DECL_LANG_SPECIFIC (NODE)			\
     && DECL_CLONED_FUNCTION (NODE) != NULL_TREE)
  
  /* If DECL_CLONED_FUNCTION_P holds, this is the function that was
--- 1959,1967 ----
  /* Nonzero if NODE (a FUNCTION_DECL) is a cloned constructor or
     destructor.  */
  #define DECL_CLONED_FUNCTION_P(NODE)		\
!   ((TREE_CODE (NODE) == FUNCTION_DECL 		\
!     || TREE_CODE (NODE) == TEMPLATE_DECL)	\
!    && DECL_LANG_SPECIFIC (NODE)			\
     && DECL_CLONED_FUNCTION (NODE) != NULL_TREE)
  
  /* If DECL_CLONED_FUNCTION_P holds, this is the function that was

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