From fd167c4784f1bb960cbc082ef335a2318aa4a54c Mon Sep 17 00:00:00 2001 From: rideout Date: Tue, 10 Apr 2007 13:22:10 +0000 Subject: * Cast the expressions for the sizes of malloc calls to size_t. This fixes PR 2088. * Check if malloc returns a null pointer, and if so die with a level 0 warning. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@487 b61c5cb5-eaca-4651-9a7a-d64986f99364 --- src/Storage.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Storage.c b/src/Storage.c index 5c9f1cb..c73e42f 100644 --- a/src/Storage.c +++ b/src/Storage.c @@ -613,7 +613,7 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, GA->padddata = NULL; } - if (GA->extras->npoints * GA->varsize * GA->vector_size <= 0) + if ((size_t) GA->extras->npoints * GA->varsize * GA->vector_size <= 0) { /* only warn if the global array size is also zero */ for (i = 0, global_size = 1; i < GA->extras->dim; i++) @@ -631,15 +631,22 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, else if (! my_padding_active) { /* Easy case. */ - GA->data = malloc (GA->extras->npoints * GA->varsize * GA->vector_size); + GA->data = malloc ((size_t) GA->extras->npoints * GA->varsize + * GA->vector_size); GA->padddata = GA->data; } else { /* Use the Cactus Cache alignment function */ GA->data = Util_CacheMalloc (GA->arrayid, - GA->extras->npoints * GA->varsize * GA->vector_size, - &GA->padddata); + (size_t) GA->extras->npoints * GA->varsize + * GA->vector_size, &GA->padddata); + } + if (!GA->data) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, "Error allocating memory " + "block of size %.0f", + (double) GA->extras->npoints * GA->varsize * GA->vector_size); } GA->npoints = GA->extras->npoints; #ifdef DEBUG_PUGH -- cgit v1.2.3