tarrays.c: fix remaining memory allocation - granular - granular dynamics simulation (HTM) git clone git://src.adamsgaard.dk/granular (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit f8e052c489f2843bf42b19785d6e8519d5df9075 (DIR) parent 1c5cb83233d982f7110258f1ef54fdc422c70cff (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Thu, 18 Mar 2021 14:40:34 +0100 arrays.c: fix remaining memory allocation Diffstat: M arrays.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- (DIR) diff --git a/arrays.c b/arrays.c t@@ -106,7 +106,7 @@ zeros(const int n) double *x; check_magnitude(__func__, 1, n); - if (!(x = malloc(n * sizeof(double)))) + if (!(x = calloc(n, sizeof(double)))) err(1, "%s: x calloc", __func__); for (i = 0; i < n; ++i) x[i] = 0.0; t@@ -150,8 +150,14 @@ initval(const double value, const int n) double * empty(const int n) { + double *out; + check_magnitude(__func__, 1, n); - return malloc(n * sizeof(double)); + + if (!(out = malloc(n * sizeof(double)))) + err(1, "%s: calloc", __func__); + + return out; } /* Return largest value in array `a` with size `n` */