Skip to content
Snippets Groups Projects
Commit d4e952dc authored by Moritz Hanke's avatar Moritz Hanke
Browse files

fixes bug in routine yac_point_sphere_part_search_NNN

* this bug could case a segmentation fault in nnn_search_local, if the number of unmasked point on a process was zero
parent 41cfb35b
No related branches found
No related tags found
No related merge requests found
......@@ -1445,7 +1445,11 @@ void yac_point_sphere_part_search_NNN(struct point_sphere_part_search * search,
return;
}
if (search == NULL) return;
if (search == NULL) {
memset(num_local_point_ids, 0, num_points * sizeof(*num_local_point_ids));
return;
}
struct point_sphere_part_node * base_node = &(search->base_node);
......
......@@ -42,6 +42,7 @@
#include "sphere_part.h"
static void random_test(size_t const num_points);
static void zero_point_test();
static void single_point_test();
static void empty_branch_test();
......@@ -55,6 +56,7 @@ int main(void) {
random_test(100);
random_test(650);
}
zero_point_test();
single_point_test();
empty_branch_test();
......@@ -210,6 +212,44 @@ static void single_point_test() {
yac_delete_point_sphere_part_search(search);
}
static void zero_point_test() {
struct point_sphere_part_search * search =
yac_point_sphere_part_search_new(0, NULL);
double x_coordinates[] = {0.0,90.0,180.0,-90.0, 0.0, 0.0};
double y_coordinates[] = {0.0, 0.0, 0.0, 0.0,90.0,-90.0};
size_t num_points = sizeof(x_coordinates) / sizeof(x_coordinates[0]);
double xyz_coordinates[num_points][3];
for (size_t i = 0; i < num_points; ++i)
LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
size_t * local_point_ids = NULL;
size_t local_point_ids_array_size = 0;
size_t * num_local_point_ids =
malloc(num_points * sizeof(*num_local_point_ids));
for (size_t i = 0; i < num_points; ++i) num_local_point_ids[i] = -1;
yac_point_sphere_part_search_NN(
search, num_points, xyz_coordinates, NULL, NULL, NULL, &local_point_ids,
&local_point_ids_array_size, num_local_point_ids);
for (size_t i = 0; i < num_points; ++i)
if (num_local_point_ids[i] != 0) PUT_ERR("zero_point_test: wrong result\n");
for (size_t i = 0; i < num_points; ++i) num_local_point_ids[i] = -1;
yac_point_sphere_part_search_NNN(
search, num_points, xyz_coordinates, 16, NULL, NULL, NULL, NULL,
&local_point_ids, &local_point_ids_array_size, num_local_point_ids);
for (size_t i = 0; i < num_points; ++i)
if (num_local_point_ids[i] != 0) PUT_ERR("zero_point_test: wrong result\n");
free(local_point_ids);
free(num_local_point_ids);
yac_delete_point_sphere_part_search(search);
}
static void empty_branch_test() {
double x_coordinates_a[] = {0.0,0.0,0.0,0.0};
......@@ -248,6 +288,7 @@ static void empty_branch_test() {
compare_distance_index);
}
for (size_t i = 0; i < num_points_b; ++i) num_local_point_ids[i] = -1;
yac_point_sphere_part_search_NN(
search, num_points_b, xyz_coordinates_b, NULL, NULL, NULL,
&local_point_ids, &local_point_ids_array_size, num_local_point_ids);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment