Commit fd682925 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

When computing the top-level cell index of particles, check that the positions...

When computing the top-level cell index of particles, check that the positions are valid before accessing the array.
parent 223d8044
......@@ -1062,8 +1062,6 @@ void space_parts_get_cell_index_mapper(void *map_data, int nr_parts,
/* Get its cell index */
const int index =
cell_getid(cdim, pos_x * ih_x, pos_y * ih_y, pos_z * ih_z);
ind[k] = index;
cell_counts[index]++;
#ifdef SWIFT_DEBUG_CHECKS
if (index < 0 || index >= cdim[0] * cdim[1] * cdim[2])
......@@ -1076,6 +1074,9 @@ void space_parts_get_cell_index_mapper(void *map_data, int nr_parts,
pos_z);
#endif
ind[k] = index;
cell_counts[index]++;
/* Compute minimal mass */
min_mass = min(min_mass, hydro_get_mass(p));
......@@ -1149,8 +1150,6 @@ void space_gparts_get_cell_index_mapper(void *map_data, int nr_gparts,
/* Get its cell index */
const int index =
cell_getid(cdim, pos_x * ih_x, pos_y * ih_y, pos_z * ih_z);
ind[k] = index;
cell_counts[index]++;
#ifdef SWIFT_DEBUG_CHECKS
if (index < 0 || index >= cdim[0] * cdim[1] * cdim[2])
......@@ -1163,6 +1162,9 @@ void space_gparts_get_cell_index_mapper(void *map_data, int nr_gparts,
pos_z);
#endif
ind[k] = index;
cell_counts[index]++;
/* Compute minimal mass */
if (gp->type == swift_type_dark_matter) {
min_mass = min(min_mass, gp->mass);
......@@ -1238,8 +1240,6 @@ void space_sparts_get_cell_index_mapper(void *map_data, int nr_sparts,
/* Get its cell index */
const int index =
cell_getid(cdim, pos_x * ih_x, pos_y * ih_y, pos_z * ih_z);
ind[k] = index;
cell_counts[index]++;
#ifdef SWIFT_DEBUG_CHECKS
if (index < 0 || index >= cdim[0] * cdim[1] * cdim[2])
......@@ -1252,6 +1252,9 @@ void space_sparts_get_cell_index_mapper(void *map_data, int nr_sparts,
pos_z);
#endif
ind[k] = index;
cell_counts[index]++;
/* Compute minimal mass */
min_mass = min(min_mass, sp->mass);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment