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]

[patch] Remove possible null dereferences.


 Hi,

  I encountered a couple warnings while bootstrapping gcc, with java this time,
with my null dereference patch[1].

  The change it PUSH_FIELD changes a segfault into an abort.

  The change to find_most_specific_methods_list seems to be neccesary since
the optimizers don't seem to be able to figure out that if LIST is NULL_TREE
then max will be 0 and NULL_TREE will be returned.  I don't think it's such
a bad change.  The diff of parse.c.t48.dom3 before and after the change to
find_most_specific_methods_list removes about 87 lines from the output:

~/cvs/build/gcc$ diff -up parse.c.t48.dom3 parse.c.t48.dom3.good | diffstat
 parse.c.t48.dom3 | 4485 ++++++++++++++++++++++++++-----------------------------
 1 files changed, 2199 insertions(+), 2286 deletions(-)


Jim
[1] http://gcc.gnu.org/ml/gcc-patches/2004-07/msg00423.html -- Rejected, 
Diego said it should go into CCP if it goes anywhere.


2004-07-08  James Morrison  <phython@gcc.gnu.org>

	* java-tree.h (PUSH_FIELD): Abort if TYPE_FIELDS(RTYPE) and FIELD are
	both NULL_TREE.
	* parse.y (find_most_specific_methods_list): Immediatly return if
	LIST is NULL_TREE.

Index: gcc/java/java-tree.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.207
diff -u -u -p -r1.207 java-tree.h
--- gcc/java/java-tree.h	7 Jul 2004 10:21:00 -0000	1.207
+++ gcc/java/java-tree.h	9 Jul 2004 01:50:42 -0000
@@ -1698,6 +1698,8 @@ extern tree *type_map;
 { tree _field = build_decl (FIELD_DECL, get_identifier ((NAME)), (FTYPE)); \
   if (TYPE_FIELDS (RTYPE) == NULL_TREE)	\
     TYPE_FIELDS (RTYPE) = _field; 	\
+  else if (FIELD == NULL_TREE)          \
+    abort ();                           \
   else					\
     TREE_CHAIN(FIELD) = _field;		\
   DECL_CONTEXT (_field) = (RTYPE);	\
Index: gcc/java/parse.y
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.490
diff -u -u -p -r1.490 parse.y
--- gcc/java/parse.y	7 Jul 2004 10:21:01 -0000	1.490
+++ gcc/java/parse.y	9 Jul 2004 01:50:43 -0000
@@ -11143,6 +11143,10 @@ find_most_specific_methods_list (tree li
   int max = 0;
   int abstract, candidates;
   tree current, new_list = NULL_TREE;
+
+  if (list == NULL_TREE)
+    return NULL_TREE;
+
   for (current = list; current; current = TREE_CHAIN (current))
     {
       tree method;


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