aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorAlexandra Tolstikova <alexandra.tolstikova@desy.de>2015-10-30 13:39:53 +0100
committerThomas White <taw@physics.org>2017-02-01 16:04:31 +0100
commit91ba89c68c263daaa7bd903cdf33de0b11c1642b (patch)
tree1998c9de96f663fca5bdcbeb3fc3e0e7eab957e1 /libcrystfel
parentd03c456a838bdebf30e8b508885f0f0907618c00 (diff)
Fix malloc fail due to integer overflow in N_triplets
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/asdf.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/libcrystfel/src/asdf.c b/libcrystfel/src/asdf.c
index 94d993cf..bf2ce342 100644
--- a/libcrystfel/src/asdf.c
+++ b/libcrystfel/src/asdf.c
@@ -915,10 +915,13 @@ static int **generate_triplets(int N_reflections, int N_triplets_max, int *N)
int N_triplets = N_reflections * (N_reflections - 1) *
(N_reflections - 2) / 6;
- if ( N_triplets > N_triplets_max ) N_triplets = N_triplets_max;
+ if ( N_triplets > N_triplets_max || N_reflections > 1000 ) {
+ N_triplets = N_triplets_max;
+ }
*N = N_triplets;
int **triplets = malloc(N_triplets * sizeof(int *));
+
if (triplets == NULL) {
ERROR("Failed to allocate triplets in generate_triplets!\n");
return 0;