summaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2001-10-02 13:44:32 +0000
committerTom Tromey <tromey@gcc.gnu.org>2001-10-02 13:44:32 +0000
commit62a040818aae81ad8558ebbe3c8973a16e7c250f (patch)
tree671927c18dd4a69605e4bc5e6e956d6b870a48d6 /libjava
parent6cbd1b6f7ebf08244942dd1aaae5ae73ef79da48 (diff)
downloadgcc-62a040818aae81ad8558ebbe3c8973a16e7c250f.tar.gz
prims.cc (_Jv_NewMultiArrayUnchecked): New method.
* 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. From-SVN: r45951
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog10
-rw-r--r--libjava/java/lang/reflect/natArray.cc5
-rw-r--r--libjava/java/lang/reflect/natMethod.cc4
-rw-r--r--libjava/prims.cc24
4 files changed, 34 insertions, 9 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index c7e3a57c6a8..ee54950d0d1 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,13 @@
+2001-10-01 Tom Tromey <tromey@redhat.com>
+
+ * 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.
+
2001-10-01 Mark Wielaard <mark@klomp.org>
* java/io/FileWriter.java: Merge with Classpath.
diff --git a/libjava/java/lang/reflect/natArray.cc b/libjava/java/lang/reflect/natArray.cc
index bc48041f455..78751229eab 100644
--- a/libjava/java/lang/reflect/natArray.cc
+++ b/libjava/java/lang/reflect/natArray.cc
@@ -43,11 +43,12 @@ java::lang::reflect::Array::newInstance (jclass componentType, jint length)
}
jobject
-java::lang::reflect::Array::newInstance (jclass componentType, jintArray dimensions)
+java::lang::reflect::Array::newInstance (jclass componentType,
+ jintArray dimensions)
{
jint ndims = dimensions->length;
if (ndims == 0)
- return componentType->newInstance ();
+ throw new java::lang::IllegalArgumentException ();
jint* dims = elements (dimensions);
if (ndims == 1)
return newInstance (componentType, dims[0]);
diff --git a/libjava/java/lang/reflect/natMethod.cc b/libjava/java/lang/reflect/natMethod.cc
index 96cc13209ab..26c270e3e03 100644
--- a/libjava/java/lang/reflect/natMethod.cc
+++ b/libjava/java/lang/reflect/natMethod.cc
@@ -100,8 +100,8 @@ can_widen (jclass from, jclass to)
// Boolean arguments may not be widened.
if (fromx == BOOLEAN && tox != BOOLEAN)
return false;
- // Special-case short->char conversions.
- if (fromx == SHORT && tox == CHAR)
+ // Nothing promotes to char.
+ if (tox == CHAR && fromx != CHAR)
return false;
return fromx <= tox;
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);
}