* src/vm/array.c (array_element_get): Do a null-pointer check.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 20 Mar 2008 16:55:56 +0000 (17:55 +0100)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 20 Mar 2008 16:55:56 +0000 (17:55 +0100)
(array_element_primitive_get): Likewise.
(array_element_primitive_set): Likewise.
(array_objectarray_element_set): Check if the object can be stored in
the array.

src/vm/array.c

index c3b694b52ab17295b9c7ceba064b9fb058c60cf7..b517b4e428b54309ffd2afaf49ddac94c7139a7f 100644 (file)
@@ -49,6 +49,11 @@ java_handle_t *array_element_get(java_handle_t *a, int32_t index)
        imm_union      value;
        java_handle_t *o;
 
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
        v = LLNI_vftbl_direct(a);
 
        type = v->arraydesc->arraytype;
@@ -89,6 +94,12 @@ imm_union array_element_primitive_get(java_handle_t *a, int32_t index)
        int       type;
        imm_union value;
 
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               value.a = NULL;
+               return value;
+       }
+
        v = LLNI_vftbl_direct(a);
 
        type = v->arraydesc->arraytype;
@@ -149,6 +160,11 @@ void array_element_primitive_set(java_handle_t *a, int32_t index, imm_union valu
        vftbl_t *v;
        int      type;
 
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               return;
+       }
+
        v = LLNI_vftbl_direct(a);
 
        type = v->arraydesc->arraytype;
@@ -288,13 +304,33 @@ void array_##name##array_element_set(java_handle_##name##array_t *a, int32_t ind
 
 void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
 {
-       int32_t size;
+       arraydescriptor *ad;
+       classinfo *cc;
+       int32_t    size;
 
        if (a == NULL) {
                exceptions_throw_nullpointerexception();
                return;
        }
 
+       /* TODO Write inline functions for that and use LLNI. */
+
+       LLNI_CRITICAL_START;
+
+       ad = a->header.objheader.vftbl->arraydesc;
+       cc = ad->componentvftbl->class;
+
+       LLNI_CRITICAL_END;
+
+       if (ad->arraytype == ARRAYTYPE_OBJECT) {
+               if (value != NULL) {
+                       if (builtin_instanceof(value, cc) == false) {
+                               exceptions_throw_illegalargumentexception();
+                               return;
+                       }
+               }
+       }
+
        size = LLNI_array_size(a);
 
        if ((index < 0) || (index >= size)) {