From e7a3e95d815446986410cf338fea46503f1a7100 Mon Sep 17 00:00:00 2001 From: schnetter Date: Mon, 26 Sep 2005 00:26:12 +0000 Subject: Insert several checks whether variable indices passed into routines are legal, and whether malloc returned a null pointer. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@468 b61c5cb5-eaca-4651-9a7a-d64986f99364 --- src/Comm.c | 25 +++++++++++++++++++++++-- src/PughUtils.c | 6 ++++++ src/SetupGroup.c | 4 ++-- src/Storage.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Comm.c b/src/Comm.c index 0c36af8..bd7f453 100644 --- a/src/Comm.c +++ b/src/Comm.c @@ -88,7 +88,14 @@ int PUGH_SyncGroup(const cGH *GH, const char *groupname) { CCTK_GroupData(group, &pgroup); - retval = PUGH_SyncGArrayGroup(PUGH_pGH(GH), CCTK_FirstVarIndexI(group)); + if (pgroup.numvars == 0) + { + retval = 0; + } + else + { + retval = PUGH_SyncGArrayGroup(PUGH_pGH(GH), CCTK_FirstVarIndexI(group)); + } } return (retval); @@ -192,6 +199,10 @@ int PUGH_DisableGroupComm(const cGH *GH, const char *groupname) CCTK_GroupData(group, &pgroup); first_var = CCTK_FirstVarIndexI(group); + if (first_var < 0) + { + CCTK_WARN (0, "Illegal group index -- group has no variables"); + } pughGH = PUGH_pGH(GH); GA = (pGA *) pughGH->variables[first_var][0]; @@ -388,6 +399,11 @@ int PUGH_DisableGArrayGroupComm(pGH *pughGH, int first_var, pComm *groupcomm) pGA *GA; /* first variable in group */ + if (first_var < 0) + { + CCTK_WARN (0, "Illegal variable index"); + } + GA = (pGA *) pughGH->variables[first_var][0]; #ifdef DEBUG_PUGH @@ -470,6 +486,11 @@ static int PUGH_EnableGArrayGroupComm(pGH *pughGH, int first_var, int commflag) pGA *GA; /* first variable in group */ + if (first_var < 0) + { + CCTK_WARN (0, "Illegal variable index"); + } + GA = pughGH->variables [first_var][0]; #ifdef DEBUG_PUGH @@ -972,7 +993,7 @@ static int PUGH_SyncSingleProc(pGH *pughGH, pComm *comm) return (0); } - /* since we need to iterators here we need to allocate one */ + /* since we need two iterators here we need to allocate one */ iterator_from = GA->extras->iterator; iterator_to = (int *) malloc (GA->extras->dim * sizeof (int)); diff --git a/src/PughUtils.c b/src/PughUtils.c index 5bb9238..1c9eabf 100644 --- a/src/PughUtils.c +++ b/src/PughUtils.c @@ -56,6 +56,12 @@ const int *PUGH_Topology (const cGH *GH, int dim) { pGH *pughGH; + + if (dim <= 0) + { + CCTK_WARN (0, "Illegal dimension"); + } + pughGH = PUGH_pGH (GH); return pughGH->Connectivity[dim-1]->nprocs; diff --git a/src/SetupGroup.c b/src/SetupGroup.c index 8fdca77..7a93391 100644 --- a/src/SetupGroup.c +++ b/src/SetupGroup.c @@ -174,7 +174,7 @@ static int PUGH_SetupGAGroup (pGH *newGH, /* Set up the communication buffer used for all variables within this group. Note: only with allocated buffers we can have group communication. */ groupcomm = NULL; - if(newGH->commmodel == PUGH_ALLOCATEDBUFFERS) + if(n_variables > 0 && newGH->commmodel == PUGH_ALLOCATEDBUFFERS) { groupcomm = PUGH_SetupGArrayGroupComm (newGH, dim, @@ -213,7 +213,7 @@ static int PUGH_SetupGAGroup (pGH *newGH, staggercode, vectorlength, variable%vectorlength, - variable%vectorlength > 0 ? newGH->variables[newGH->nvariables-variable%vectorlength][level] : NULL); + variable%vectorlength > 0 ? newGH->variables[newGH->nvariables - variable%vectorlength][level] : NULL); newGH->narrays++; } newGH->nvariables++; diff --git a/src/Storage.c b/src/Storage.c index acfec4b..c3f8b6f 100644 --- a/src/Storage.c +++ b/src/Storage.c @@ -427,6 +427,10 @@ int PUGH_DisableGroupStorage (const cGH *GH, const char *groupname) /* get global index of first variable in group */ first_var = CCTK_FirstVarIndexI (group); + if (first_var < 0) + { + CCTK_WARN (0, "Illegal group index -- group has no variables"); + } variables = (pGA ***) PUGH_pGH (GH)->variables; @@ -1145,6 +1149,12 @@ static int PUGHi_EnableGArrayGroupStorage (pGH *pughGH, pGA *GA; int level; + + if (first_var < 0) + { + CCTK_WARN (0, "Illegal variable index"); + } + retval = 0; nstorage = 0; nnostorage = 0; @@ -1249,6 +1259,12 @@ static int PUGHi_DisableGArrayGroupStorage (pGH *pughGH, pGA *GA; int level; + + if (first_var < 0) + { + CCTK_WARN (0, "Illegal variable index"); + } + retval = 0; nstorage = 0; nnostorage = 0; @@ -1320,6 +1336,12 @@ int PUGH_NumTimeLevels(const pGH *pughGH, int var) int timelevels; + + if (var < 0) + { + CCTK_WARN (0, "Illegal variable index"); + } + timelevels = CCTK_MaxTimeLevelsVI(var); retval = PUGHi_NumTimeLevelsArray(pughGH, var, timelevels); @@ -1359,6 +1381,12 @@ int PUGHi_NumTimeLevelsArray(const pGH *pughGH, int var, int timelevels) int level; pGA *GA; + + if (var < 0) + { + CCTK_WARN (0, "Illegal variable index"); + } + retval = 0; for (level = 0; level < timelevels; level++) -- cgit v1.2.3