diff options
author | rideout <rideout@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2007-04-10 13:22:10 +0000 |
---|---|---|
committer | rideout <rideout@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2007-04-10 13:22:10 +0000 |
commit | fd167c4784f1bb960cbc082ef335a2318aa4a54c (patch) | |
tree | 8796e24acb666d4ba967cb2b090efa0c9867b3cc /src | |
parent | 726b972d163cff25ef3513200e88fcd34a12a4df (diff) |
* 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
Diffstat (limited to 'src')
-rw-r--r-- | src/Storage.c | 15 |
1 files 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 |