cngf-pf

continuum model for granular flows with pore-pressure dynamics (renamed from 1d_fd_simple_shear)
git clone git://src.adamsgaard.dk/cngf-pf # fast
git clone https://src.adamsgaard.dk/cngf-pf.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit 1e6942b9f9ad1018f0ed75947ebe69cda5b047f5
parent ee23eff931ba11a8789ed2d47b9b42802da4fa7d
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 18 Mar 2021 14:41:37 +0100

arrays.[ch]: check memory allocation and exit on fail, add some helper functions

Diffstat:
Marrays.c | 10++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arrays.c b/arrays.c @@ -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; @@ -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` */