From 0c40b766d224202b2aee5800eed55a77daeb9dd4 Mon Sep 17 00:00:00 2001 From: msoroush Date: Sun, 6 Oct 2019 13:58:38 -0400 Subject: [PATCH] Suggested fix to the issue #143 and #123 --- src/CellList.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CellList.h b/src/CellList.h index 88c9748b3..09da998e9 100644 --- a/src/CellList.h +++ b/src/CellList.h @@ -85,6 +85,12 @@ inline int CellList::PositionToCell(const XYZ& posRef, int box) const int x = (int)(pos.x / cellSize[box].x); int y = (int)(pos.y / cellSize[box].y); int z = (int)(pos.z / cellSize[box].z); + //Check the cell number to avoid segfult for coordinates close to axis + //x, y, and z should never be equal or greater than number of cells in x, y, + // and z axis, respectively. + x -= (x == edgeCells[box][0] ? 1 : 0); + y -= (y == edgeCells[box][1] ? 1 : 0); + z -= (z == edgeCells[box][2] ? 1 : 0); return x * edgeCells[box][1] * edgeCells[box][2] + y * edgeCells[box][2] + z; }