From a4f7feb9ff7bec919e81ad3360ca11e5a6b480b2 Mon Sep 17 00:00:00 2001
From: James Willis <james.s.willis@durham.ac.uk>
Date: Wed, 4 Oct 2017 12:08:19 +0100
Subject: [PATCH] Fixed bug where max_index_i could be count_j instead of
 count_j - 1. Also fixed bug where an exit iteration of 0 prevents the inner
 loop from executing.

---
 src/runner_doiact_vec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/runner_doiact_vec.c b/src/runner_doiact_vec.c
index 5aef983322..fb338b50c3 100644
--- a/src/runner_doiact_vec.c
+++ b/src/runner_doiact_vec.c
@@ -289,7 +289,7 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
         sort_i[first_pi].d + pi->h * kernel_gamma + dx_max - rshift;
 
     /* Loop through particles in cell j until they are not in range of pi. */
-    while (temp < cj->count && first_di > sort_j[temp].d) temp++;
+    while (temp < cj->count - 1 && first_di > sort_j[temp].d) temp++;
 
     max_index_i[first_pi] = temp;
 
@@ -300,7 +300,7 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
 
       const float di = sort_i[i].d + pi->h * kernel_gamma + dx_max - rshift;
 
-      while (temp < cj->count && di > sort_j[temp].d) temp++;
+      while (temp < cj->count - 1 && di > sort_j[temp].d) temp++;
 
       max_index_i[i] = temp;
     }
@@ -1170,7 +1170,7 @@ void runner_dopair1_density_vec(struct runner *r, struct cell *ci,
       vector pjx, pjy, pjz;
 
       /* Loop over the parts in cj. */
-      for (int pjd = 0; pjd < exit_iteration_align; pjd += VEC_SIZE) {
+      for (int pjd = 0; pjd <= exit_iteration_align; pjd += VEC_SIZE) {
 
         /* Get the cache index to the jth particle. */
         int cj_cache_idx = pjd;
-- 
GitLab