This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
patch to fix null-pointer failure in libjava/boehm.cc
- From: Per Bothner <per at bothner dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Sat, 26 Mar 2005 12:21:00 -0800
- Subject: patch to fix null-pointer failure in libjava/boehm.cc
I don't know if this is quite right. I don't know this code at all,
and I'm curious if there was a reason for dereferencing field->u.addr
twice in the original code.
Is this appropriate for 4.0 - or perhaps 4.0.1? Perhaps if Hans and
others more familiar with this code agree it is safe. At least this
minimal version should be definitely safe:
- if (JvFieldIsRef (field) && field->isResolved())
+ if (JvFieldIsRef (field) && p && field->isResolved())
Here is the analysis of the bug;
http://gcc.gnu.org/ml/java/2005-03/msg00141.html
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2005-03-26 Per Bothner <per@bothner.com>
* boehm.cc (_Jv_MarkObj): Don't follow null pointer to static field,
which can happen if class is JV_STATE_LOADED but not JV_STATE_PREPARED.
Index: boehm.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/boehm.cc,v
retrieving revision 1.45
diff -u -p -r1.45 boehm.cc
--- boehm.cc 25 Nov 2004 03:46:53 -0000 1.45
+++ boehm.cc 25 Mar 2005 18:42:07 -0000
@@ -189,9 +189,11 @@ _Jv_MarkObj (void *addr, void *msp, void
// mark also the value pointed to. We check for isResolved
// since marking can happen before memory is allocated for
// static members.
- if (JvFieldIsRef (field) && field->isResolved())
+ // Note that field->u.addr may be null if the class c is
+ // JV_STATE_LOADED but not JV_STATE_PREPARED (initialized).
+ if (JvFieldIsRef (field) && p && field->isResolved())
{
- jobject val = *(jobject*) field->u.addr;
+ jobject val = *(jobject*) p;
p = (GC_PTR) val;
MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c);
}