Patch: incorrect hardcoding of java's modifier_ctx array size

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Thu Jun 20 08:10:00 GMT 2002


While grepping for places to use ARRAY_SIZE, I noticed some incorrect
hardcoding of the size of java's parser_ctxt.modifier_ctx[] array.
See: http://gcc.gnu.org/ml/gcc-patches/2002-03/msg01675.html for some
history.

NOTE, there might be other places where the size is hardcoded, I just
found these by chance.  (When I noticed the lex.c bug, I just did grep
-n -w 11 java/*.[chy] and quickly found the parse.y bug too.).

I'm not aware of any actual bugs caused by this, perhaps we just get
lucky.  However this patch might be relevant to 3.1.x too.

Tested on the trunk for sparc-sun-solaris2.7, no java regressions.  Ok
to install on the trunk (and perhaps branch?)

		Thanks,
		--Kaveh


2002-06-19  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* lex.c (java_init_lex): Avoid incorrect hardcoded constant 11.
	* parse.y (mark_parser_ctxt): Likewise.

diff -rup orig/egcc-CVS20020619/gcc/java/lex.c egcc-CVS20020619/gcc/java/lex.c
--- orig/egcc-CVS20020619/gcc/java/lex.c	2002-06-11 16:01:40.000000000 -0400
+++ egcc-CVS20020619/gcc/java/lex.c	2002-06-19 22:41:22.284119186 -0400
@@ -128,7 +128,7 @@ java_init_lex (finput, encoding)
   CPC_INITIALIZER_LIST (ctxp) = CPC_STATIC_INITIALIZER_LIST (ctxp) =
     CPC_INSTANCE_INITIALIZER_LIST (ctxp) = NULL_TREE;
 
-  memset ((PTR) ctxp->modifier_ctx, 0, 11*sizeof (ctxp->modifier_ctx[0]));
+  memset ((PTR) ctxp->modifier_ctx, 0, sizeof (ctxp->modifier_ctx));
   memset ((PTR) current_jcf, 0, sizeof (JCF));
   ctxp->current_parsed_class = NULL;
   ctxp->package = NULL_TREE;
diff -rup orig/egcc-CVS20020619/gcc/java/parse.y egcc-CVS20020619/gcc/java/parse.y
--- orig/egcc-CVS20020619/gcc/java/parse.y	2002-06-13 16:01:03.000000000 -0400
+++ egcc-CVS20020619/gcc/java/parse.y	2002-06-19 22:44:53.585644309 -0400
@@ -16148,13 +16148,15 @@ mark_parser_ctxt (p)
      void *p;
 {
   struct parser_ctxt *pc = *((struct parser_ctxt **) p);
-  int i;
+#ifndef JC1_LITE
+  size_t i;
+#endif
 
   if (!pc)
     return;
 
 #ifndef JC1_LITE
-  for (i = 0; i < 11; ++i)
+  for (i = 0; i < ARRAY_SIZE (pc->modifier_ctx); ++i)
     ggc_mark_tree (pc->modifier_ctx[i]);
   ggc_mark_tree (pc->class_type);
   ggc_mark_tree (pc->function_decl);



More information about the Java-patches mailing list