Merged with tip.
[cacao.git] / src / vm / builtin.c
index 52c5c10de24442bc8b8a6392e2373e7f5f872530..377bad8830fd3370390200d55b26348f91e13fd7 100644 (file)
@@ -65,7 +65,7 @@
 #include "vm/exceptions.h"
 #include "vm/global.h"
 #include "vm/initialize.h"
-#include "vm/primitive.h"
+#include "vm/primitive.hpp"
 #include "vm/stringlocal.h"
 
 #include "vm/jit/asmpart.h"
@@ -416,16 +416,16 @@ bool builtintable_replace_function(void *iptr_)
 
 *******************************************************************************/
 
-bool builtin_instanceof(java_handle_t *o, classinfo *class)
+bool builtin_instanceof(java_handle_t *o, classinfo *c)
 {
-       classinfo *c;
+       classinfo *oc;
 
        if (o == NULL)
                return 0;
 
-       LLNI_class_get(o, c);
+       LLNI_class_get(o, oc);
 
-       return class_isanysubclass(c, class);
+       return class_isanysubclass(oc, c);
 }
 
 
@@ -439,16 +439,16 @@ bool builtin_instanceof(java_handle_t *o, classinfo *class)
 
 *******************************************************************************/
 
-bool builtin_checkcast(java_handle_t *o, classinfo *class)
+bool builtin_checkcast(java_handle_t *o, classinfo *c)
 {
-       classinfo *c;
+       classinfo *oc;
 
        if (o == NULL)
                return 1;
 
-       LLNI_class_get(o, c);
+       LLNI_class_get(o, oc);
 
-       if (class_isanysubclass(c, class))
+       if (class_isanysubclass(oc, c))
                return 1;
 
        return 0;
@@ -2207,15 +2207,24 @@ void builtin_arraycopy(java_handle_t *src, s4 srcStart,
                return;
        }
 
-       /* we try to throw exception with the same message as SUN does */
+       // Check if offsets and length are positive.
+       if ((srcStart < 0) || (destStart < 0) || (len < 0)) {
+               exceptions_throw_arrayindexoutofboundsexception();
+               return;
+       }
 
-       if ((len < 0) || (srcStart < 0) || (destStart < 0) ||
-               (srcStart  + len < 0) || (srcStart  + len > LLNI_array_size(src)) ||
-               (destStart + len < 0) || (destStart + len > LLNI_array_size(dest))) {
+       // Check if ranges are valid.
+       if ((((uint32_t) srcStart  + (uint32_t) len) > (uint32_t) LLNI_array_size(src)) ||
+               (((uint32_t) destStart + (uint32_t) len) > (uint32_t) LLNI_array_size(dest))) {
                exceptions_throw_arrayindexoutofboundsexception();
                return;
        }
 
+       // Special case.
+       if (len == 0) {
+               return;
+       }
+
        if (sdesc->componentvftbl == ddesc->componentvftbl) {
                /* We copy primitive values or references of exactly the same type */