--- modules/yaksa/src/frontend/types/yaksa_indexed.c	2021-10-19 20:54:27.853715399 +0200
+++ modules/yaksa/src/frontend/types/yaksa_indexed.c	2021-10-20 00:29:34.193739206 +0200
@@ -40,11 +40,15 @@
 
     outtype->size = 0;
     for (int i = 0; i < count; i++)
-        outtype->size += intype->size * array_of_blocklengths[i];
+        outtype->size += intype->size * (uintptr_t)array_of_blocklengths[i];
     outtype->alignment = intype->alignment;
 
     int is_set;
+    intptr_t last_ub;
+    int is_noncontig;
     is_set = 0;
+    last_ub = 0;
+    is_noncontig = 0;
     for (int idx = 0; idx < count; idx++) {
         if (array_of_blocklengths[idx] == 0)
             continue;
@@ -60,6 +64,11 @@
             ub = array_of_displs[idx] + intype->ub;
         }
 
+        if (idx > 0 && lb != last_ub) {
+            is_noncontig = 1;
+        }
+        last_ub = ub;
+
         intptr_t true_lb = lb - intype->lb + intype->true_lb;
         intptr_t true_ub = ub - intype->ub + intype->true_ub;
 
@@ -81,8 +90,8 @@
     outtype->extent = outtype->ub - outtype->lb;
 
     outtype->u.hindexed.count = count;
-    outtype->u.hindexed.array_of_blocklengths = (int *) malloc(count * sizeof(intptr_t));
-    outtype->u.hindexed.array_of_displs = (intptr_t *) malloc(count * sizeof(intptr_t));
+    outtype->u.hindexed.array_of_blocklengths = (int *) malloc((size_t)count * sizeof(intptr_t));
+    outtype->u.hindexed.array_of_displs = (intptr_t *) malloc((size_t)count * sizeof(intptr_t));
     for (int i = 0; i < count; i++) {
         outtype->u.hindexed.array_of_blocklengths[i] = array_of_blocklengths[i];
         outtype->u.hindexed.array_of_displs[i] = array_of_displs[i];
@@ -90,26 +99,8 @@
     outtype->u.hindexed.child = intype;
 
     /* detect if the outtype is contiguous */
-    if (intype->is_contig && ((outtype->ub - outtype->lb) == outtype->size)) {
+    if (!is_noncontig && intype->is_contig) {
         outtype->is_contig = true;
-
-        int left = 0;
-        while (array_of_blocklengths[left] == 0)
-            left++;
-        int right = left + 1;
-        while (right < count && array_of_blocklengths[right] == 0)
-            right++;
-        while (right < count) {
-            if (array_of_displs[right] <= array_of_displs[left]) {
-                outtype->is_contig = false;
-                break;
-            } else {
-                left = right;
-                right++;
-                while (right < count && array_of_blocklengths[right] == 0)
-                    right++;
-            }
-        }
     } else {
         outtype->is_contig = false;
     }
@@ -125,7 +116,7 @@
     } else {
         uintptr_t tmp = 0;
         for (int i = 0; i < count; i++)
-            tmp += array_of_blocklengths[i];
+            tmp += (uintptr_t)array_of_blocklengths[i];
         outtype->num_contig = intype->num_contig * tmp;
     }
 
@@ -142,6 +133,7 @@
                                const intptr_t * array_of_displs, yaksa_type_t oldtype,
                                yaksa_info_t info, yaksa_type_t * newtype)
 {
+    (void)info;
     int rc = YAKSA_SUCCESS;
 
     assert(yaksu_atomic_load(&yaksi_is_initialized));
@@ -153,7 +145,7 @@
     uintptr_t total_size;
     total_size = 0;
     for (int i = 0; i < count; i++) {
-        total_size += intype->size * array_of_blocklengths[i];
+        total_size += intype->size * (uintptr_t)array_of_blocklengths[i];
     }
     if (total_size == 0) {
         *newtype = YAKSA_TYPE__NULL;
@@ -178,8 +170,9 @@
                               const int *array_of_displs, yaksa_type_t oldtype,
                               yaksa_info_t info, yaksa_type_t * newtype)
 {
+    (void)info;
     int rc = YAKSA_SUCCESS;
-    intptr_t *real_array_of_displs = (intptr_t *) malloc(count * sizeof(intptr_t));
+    intptr_t *real_array_of_displs = (intptr_t *) malloc((size_t)count * sizeof(intptr_t));
 
     assert(yaksu_atomic_load(&yaksi_is_initialized));
 
@@ -190,7 +183,7 @@
     uintptr_t total_size;
     total_size = 0;
     for (int i = 0; i < count; i++) {
-        total_size += intype->size * array_of_blocklengths[i];
+        total_size += intype->size * (uintptr_t)array_of_blocklengths[i];
     }
     if (total_size == 0) {
         *newtype = YAKSA_TYPE__NULL;
