summaryrefslogtreecommitdiff
path: root/libjava/prims.cc
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-02 13:44:32 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-02 13:44:32 +0000
commit7e2f6bf5a1687ecd7ec1d70903d63e0c1307a789 (patch)
tree671927c18dd4a69605e4bc5e6e956d6b870a48d6 /libjava/prims.cc
parentaae9fec7102c688b20e367ce9681cc1af8fa6ce2 (diff)
downloadgcc-7e2f6bf5a1687ecd7ec1d70903d63e0c1307a789.tar.gz
* prims.cc (_Jv_NewMultiArrayUnchecked): New method.
(_Jv_NewMultiArray): Use it. Check each array dimension. (_Jv_NewMultiArray): Likewise. * java/lang/reflect/natMethod.cc (can_widen): Nothing promotes to `char'. * java/lang/reflect/natArray.cc (newInstance): Throw IllegalArgumentException if there are no dimensions. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45951 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/prims.cc')
-rw-r--r--libjava/prims.cc24
1 files changed, 19 insertions, 5 deletions
diff --git a/libjava/prims.cc b/libjava/prims.cc
index 6a13ed5fe75..9b4ac240df9 100644
--- a/libjava/prims.cc
+++ b/libjava/prims.cc
@@ -516,8 +516,10 @@ _Jv_NewArray (jint type, jint size)
return NULL; // Placate compiler.
}
-jobject
-_Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
+// Allocate a possibly multi-dimensional array but don't check that
+// any array length is <0.
+static jobject
+_Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
{
JvAssert (type->isArray());
jclass element_type = type->getComponentType();
@@ -533,14 +535,24 @@ _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
JvAssert (element_type->isArray());
jobject *contents = elements ((jobjectArray) result);
for (int i = 0; i < sizes[0]; ++i)
- contents[i] = _Jv_NewMultiArray (element_type, dimensions - 1,
- sizes + 1);
+ contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
+ sizes + 1);
}
return result;
}
jobject
+_Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
+{
+ for (int i = 0; i < dimensions; ++i)
+ if (sizes[i] < 0)
+ throw new java::lang::NegativeArraySizeException;
+
+ return _Jv_NewMultiArrayUnchecked (type, dimensions, sizes);
+}
+
+jobject
_Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
{
va_list args;
@@ -549,11 +561,13 @@ _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
for (int i = 0; i < dimensions; ++i)
{
jint size = va_arg (args, jint);
+ if (size < 0)
+ throw new java::lang::NegativeArraySizeException;
sizes[i] = size;
}
va_end (args);
- return _Jv_NewMultiArray (array_type, dimensions, sizes);
+ return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
}