patch for _Jv_IsAssignableFrom

Per Bothner per@bothner.com
Wed Mar 21 09:34:00 GMT 2001


I ran into this problem when (x instanceof I) for an interface I
returned true when it shouldn't have.  It turned out that the
source->ancestors[source->depth - target->depth] == target test
was accidentally succeeding, because the source->ancestors array
was being accessed outside its bounds!

Ok to check in?

2001-03-21  Per Bothner  <per@bothner.com>

	* java/lang/natClass.cc (_Jv_IsAssignableFrom):  Checking the
	ancestors array is invalid for interfaces, so do that *after*
	check that the target type is not an interface.

Index: natClass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.36.2.1
diff -u -p -r1.36.2.1 natClass.cc
--- natClass.cc	2001/02/17 01:06:45	1.36.2.1
+++ natClass.cc	2001/03/21 17:28:37
@@ -907,11 +907,8 @@ _Jv_LookupInterfaceMethodIdx (jclass kla
 jboolean
 _Jv_IsAssignableFrom (jclass target, jclass source)
 {
-  if (source == target
-      || (target == &ObjectClass && !source->isPrimitive())
-      || (source->ancestors != NULL 
-          && source->ancestors[source->depth - target->depth] == target))
-     return true;
+  if (source == target)
+    return true;
      
   // If target is array, so must source be.  
   if (target->isArray ())
@@ -943,9 +940,15 @@ _Jv_IsAssignableFrom (jclass target, jcl
 	      && cl_idt->cls.itable[offset] == target)
 	    return true;
 	}
+      return false;
     }
-    
-  return false;
+     
+  if ((target == &ObjectClass && !source->isPrimitive())
+      || (source->ancestors != NULL 
+	  && source->ancestors[source->depth - target->depth] == target))
+    return true;
+      
+ return false;
 }
 
 // Interface type checking, the slow way. Returns TRUE if IFACE is a 

-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/



More information about the Java-patches mailing list