aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-09-07 16:47:06 +0200
committerThomas White <taw@physics.org>2021-09-07 16:47:06 +0200
commitc2e7ca233c0955cc5c326b1a60a548a20dcbd739 (patch)
tree66d9a1e576c569d8a1d91eea9c5669066d238c9f /src
parent2e86c91ddf1c976b6f5ad3ab8a5ef5b2cd8bacb8 (diff)
partialator write_split: Handle zero crystals
The variable-sized array can't have zero size, so we need to check.
Diffstat (limited to 'src')
-rw-r--r--src/partialator.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/partialator.c b/src/partialator.c
index 7d2cfd7b..20d46abb 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -175,12 +175,24 @@ static void write_split(Crystal **crystals, int n_crystals, const char *outfile,
{
char tmp[1024];
RefList *split;
- Crystal *crystals1[n_crystals];
- Crystal *crystals2[n_crystals];
+ Crystal **crystals1;
+ Crystal **crystals2;
int n_crystals1 = 0;
int n_crystals2 = 0;
int i;
+ if ( n_crystals == 0 ) {
+ ERROR("No crystals for split!\n");
+ return;
+ }
+
+ crystals1 = malloc(n_crystals * sizeof(Crystal *));
+ if ( crystals1 == NULL ) return;
+
+ crystals2 = malloc(n_crystals * sizeof(Crystal *));
+ if ( crystals2 == NULL ) return;
+
+
for ( i=0; i<n_crystals; i++ ) {
if ( i % 2 ) {
crystals1[n_crystals1] = crystals[i];
@@ -196,6 +208,8 @@ static void write_split(Crystal **crystals, int n_crystals, const char *outfile,
if ( split == NULL ) {
ERROR("Not enough crystals for two way split!\n");
+ free(crystals1);
+ free(crystals2);
return;
}
@@ -210,6 +224,9 @@ static void write_split(Crystal **crystals, int n_crystals, const char *outfile,
write_reflist_2(tmp, split, sym);
free_contribs(split);
reflist_free(split);
+
+ free(crystals1);
+ free(crystals2);
}