prims.cc (_Jv_NewObjectArray): Use _Jv_GetArrayElementFromElementType.
* prims.cc (_Jv_NewObjectArray): Use _Jv_GetArrayElementFromElementType. (_Jv_NewPrimArray): Likewise. * java/lang/natObject.cc (clone): Use _Jv_GetArrayElementFromElementType instead of sizeof. * java/lang/natSystem.cc (arraycopy): Use _Jv_GetArrayElementFromElementType. * include/jvm.h (_Jv_GetArrayElementFromElementType): New function. From-SVN: r30655
This commit is contained in:
parent
fc39d37108
commit
93d4556218
@ -1,3 +1,15 @@
|
||||
1999-11-24 Tom Tromey <tromey@cygnus.com>
|
||||
|
||||
* prims.cc (_Jv_NewObjectArray): Use
|
||||
_Jv_GetArrayElementFromElementType.
|
||||
(_Jv_NewPrimArray): Likewise.
|
||||
* java/lang/natObject.cc (clone): Use
|
||||
_Jv_GetArrayElementFromElementType instead of sizeof.
|
||||
* java/lang/natSystem.cc (arraycopy): Use
|
||||
_Jv_GetArrayElementFromElementType.
|
||||
* include/jvm.h (_Jv_GetArrayElementFromElementType): New
|
||||
function.
|
||||
|
||||
1999-11-23 Bryce McKinlay <bryce@albatross.co.nz>
|
||||
|
||||
* java/net/natPlainSocketImpl.cc: Fix potential buffer overruns in
|
||||
|
@ -114,6 +114,36 @@ _Jv_HashCode (jobject obj)
|
||||
return (jint) obj;
|
||||
}
|
||||
|
||||
// Return a raw pointer to the elements of an array given the array
|
||||
// and its element type. You might think we could just pick a single
|
||||
// array type and use elements() on it, but we can't because we must
|
||||
// account for alignment of the element type.
|
||||
inline char *
|
||||
_Jv_GetArrayElementFromElementType (jobject array,
|
||||
jclass element_type)
|
||||
{
|
||||
char *elts;
|
||||
if (element_type == JvPrimClass (byte))
|
||||
elts = (char *) elements ((jbyteArray) array);
|
||||
else if (element_type == JvPrimClass (short))
|
||||
elts = (char *) elements ((jshortArray) array);
|
||||
else if (element_type == JvPrimClass (int))
|
||||
elts = (char *) elements ((jintArray) array);
|
||||
else if (element_type == JvPrimClass (long))
|
||||
elts = (char *) elements ((jlongArray) array);
|
||||
else if (element_type == JvPrimClass (boolean))
|
||||
elts = (char *) elements ((jbooleanArray) array);
|
||||
else if (element_type == JvPrimClass (char))
|
||||
elts = (char *) elements ((jcharArray) array);
|
||||
else if (element_type == JvPrimClass (float))
|
||||
elts = (char *) elements ((jfloatArray) array);
|
||||
else if (element_type == JvPrimClass (double))
|
||||
elts = (char *) elements ((jdoubleArray) array);
|
||||
else
|
||||
elts = (char *) elements ((jobjectArray) array);
|
||||
return elts;
|
||||
}
|
||||
|
||||
extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index);
|
||||
extern "C" jobject _Jv_NewArray (jint type, jint size);
|
||||
extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...);
|
||||
|
@ -84,7 +84,10 @@ java::lang::Object::clone (void)
|
||||
r = _Jv_NewObjectArray (array->length, comp, NULL);
|
||||
eltsize = sizeof (jobject);
|
||||
}
|
||||
size = sizeof (__JArray) + array->length * eltsize;
|
||||
// We can't use sizeof on __JArray because we must account for
|
||||
// alignment of the element type.
|
||||
size = (_Jv_GetArrayElementFromElementType (array, comp) - (char *) array
|
||||
+ array->length * eltsize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -124,52 +124,10 @@ java::lang::System::arraycopy (jobject src, jint src_offset,
|
||||
const size_t size = (prim ? src_comp->size()
|
||||
: sizeof elements((jobjectArray)src)[0]);
|
||||
|
||||
// In an ideal world we would do this via a virtual function in
|
||||
// __JArray. However, we can't have virtual functions in
|
||||
// __JArray due to the need to copy an array's virtual table in
|
||||
// _Jv_FindArrayClass.
|
||||
// We can't just pick a single subtype of __JArray to use due to
|
||||
// alignment concerns.
|
||||
char *src_elts = NULL;
|
||||
if (! prim)
|
||||
src_elts = (char *) elements ((jobjectArray) src);
|
||||
else if (src_comp == JvPrimClass (byte))
|
||||
src_elts = (char *) elements ((jbyteArray) src);
|
||||
else if (src_comp == JvPrimClass (short))
|
||||
src_elts = (char *) elements ((jshortArray) src);
|
||||
else if (src_comp == JvPrimClass (int))
|
||||
src_elts = (char *) elements ((jintArray) src);
|
||||
else if (src_comp == JvPrimClass (long))
|
||||
src_elts = (char *) elements ((jlongArray) src);
|
||||
else if (src_comp == JvPrimClass (boolean))
|
||||
src_elts = (char *) elements ((jbooleanArray) src);
|
||||
else if (src_comp == JvPrimClass (char))
|
||||
src_elts = (char *) elements ((jcharArray) src);
|
||||
else if (src_comp == JvPrimClass (float))
|
||||
src_elts = (char *) elements ((jfloatArray) src);
|
||||
else if (src_comp == JvPrimClass (double))
|
||||
src_elts = (char *) elements ((jdoubleArray) src);
|
||||
char *src_elts = _Jv_GetArrayElementFromElementType (src, src_comp);
|
||||
src_elts += size * src_offset;
|
||||
|
||||
char *dst_elts = NULL;
|
||||
if (! prim)
|
||||
dst_elts = (char *) elements ((jobjectArray) dst);
|
||||
else if (dst_comp == JvPrimClass (byte))
|
||||
dst_elts = (char *) elements ((jbyteArray) dst);
|
||||
else if (dst_comp == JvPrimClass (short))
|
||||
dst_elts = (char *) elements ((jshortArray) dst);
|
||||
else if (dst_comp == JvPrimClass (int))
|
||||
dst_elts = (char *) elements ((jintArray) dst);
|
||||
else if (dst_comp == JvPrimClass (long))
|
||||
dst_elts = (char *) elements ((jlongArray) dst);
|
||||
else if (dst_comp == JvPrimClass (boolean))
|
||||
dst_elts = (char *) elements ((jbooleanArray) dst);
|
||||
else if (dst_comp == JvPrimClass (char))
|
||||
dst_elts = (char *) elements ((jcharArray) dst);
|
||||
else if (dst_comp == JvPrimClass (float))
|
||||
dst_elts = (char *) elements ((jfloatArray) dst);
|
||||
else if (dst_comp == JvPrimClass (double))
|
||||
dst_elts = (char *) elements ((jdoubleArray) dst);
|
||||
char *dst_elts = _Jv_GetArrayElementFromElementType (dst, dst_comp);
|
||||
dst_elts += size * dst_offset;
|
||||
|
||||
#if HAVE_MEMMOVE
|
||||
|
@ -328,16 +328,22 @@ _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
|
||||
if (count < 0)
|
||||
JvThrow (new java::lang::NegativeArraySizeException);
|
||||
|
||||
JvAssert (! elementClass->isPrimitive ());
|
||||
|
||||
jobjectArray obj = NULL;
|
||||
size_t size = (size_t) _Jv_GetArrayElementFromElementType (obj,
|
||||
elementClass);
|
||||
|
||||
// Check for overflow.
|
||||
if ((size_t) count > (SIZE_T_MAX - sizeof (__JArray)) / sizeof (jobject))
|
||||
if ((size_t) count > (SIZE_T_MAX - size) / sizeof (jobject))
|
||||
JvThrow (no_memory);
|
||||
|
||||
size_t size = count * sizeof (jobject) + sizeof (__JArray);
|
||||
size += count * sizeof (jobject);
|
||||
|
||||
// FIXME: second argument should be "current loader" //
|
||||
jclass clas = _Jv_FindArrayClass (elementClass, 0);
|
||||
|
||||
jobjectArray obj = (jobjectArray) _Jv_AllocArray (size);
|
||||
obj = (jobjectArray) _Jv_AllocArray (size);
|
||||
if (! obj)
|
||||
JvThrow (no_memory);
|
||||
obj->length = count;
|
||||
@ -365,12 +371,15 @@ _Jv_NewPrimArray (jclass eltype, jint count)
|
||||
if (count < 0)
|
||||
JvThrow (new java::lang::NegativeArraySizeException ());
|
||||
|
||||
JvAssert (eltype->isPrimitive ());
|
||||
jobject dummy = NULL;
|
||||
size_t size = (size_t) _Jv_GetArrayElementFromElementType (dummy, eltype);
|
||||
|
||||
// Check for overflow.
|
||||
if ((size_t) count > (SIZE_T_MAX - sizeof (__JArray)) / elsize)
|
||||
if ((size_t) count > (SIZE_T_MAX - size) / elsize)
|
||||
JvThrow (no_memory);
|
||||
|
||||
__JArray *arr = (__JArray*) _Jv_AllocObj (sizeof (__JArray)
|
||||
+ elsize * count);
|
||||
__JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count);
|
||||
if (! arr)
|
||||
JvThrow (no_memory);
|
||||
arr->length = count;
|
||||
|
Loading…
Reference in New Issue
Block a user