summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-01-21 03:01:30 +0000
committereschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-01-21 03:01:30 +0000
commit9fcf05ef95edf68fb34699106b30ae415fde1c98 (patch)
treec05f42b83c75d28d3f93ec13ca38dd27cf8294cc /src
parenta8897d886ac87d3dddcaa565a07959289df3d0bc (diff)
Don't crash when activating non-existing thorns
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4946 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r--src/main/ActiveThorns.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/main/ActiveThorns.c b/src/main/ActiveThorns.c
index a7b0730c..4d6438ac 100644
--- a/src/main/ActiveThorns.c
+++ b/src/main/ActiveThorns.c
@@ -910,6 +910,7 @@ int CCTKi_ActivateThorns(const char *activethornlist)
const char *this_imp;
int n_warnings;
int n_errors;
+ t_sktree *thornnode;
t_sktree *impnode;
t_sktree *impthornlist;
@@ -937,10 +938,17 @@ int CCTKi_ActivateThorns(const char *activethornlist)
/* Parse list of activated thorns */
for(token = strtok(local_list, " \t\n"); token; token = strtok(NULL," \t\n"))
{
- if (! Util_StringListAdd(activated_thorns, token))
+ switch (Util_StringListAdd(activated_thorns, token))
{
+ case 1:
+ /* Thorn was added; do nothing */
+ break;
+ case 0:
printf("Warning: thorn %s already scheduled for activation\n", token);
n_warnings++;
+ break;
+ default:
+ CCTK_Warn(0, __LINE__, __FILE__, "Cactus", "Internal error");
}
}
@@ -948,37 +956,40 @@ int CCTKi_ActivateThorns(const char *activethornlist)
did_add_thorns = 1;
while(did_add_thorns) {
new_thorns = Util_StringListCreate(n_thorns);
- // Copy existing thorns
+ /* Copy existing thorns */
for(thorn = Util_StringListNext(activated_thorns,1); thorn;
thorn = Util_StringListNext(activated_thorns,0))
{
Util_StringListAdd(new_thorns, thorn);
}
- // Add all thorns activated by these thorns
+ /* Add all thorns activated by these thorns */
did_add_thorns = 0;
for(thorn = Util_StringListNext(activated_thorns,1); thorn;
thorn = Util_StringListNext(activated_thorns,0))
{
- this_thorn = ((t_sktree *) SKTreeFindNode(thornlist, thorn))->data;
- if(this_thorn && this_thorn->activates_thorns)
- {
- for(i = 0; this_thorn->activates_thorns[i]; i++)
+ thornnode = SKTreeFindNode(thornlist, thorn);
+ if(thornnode) {
+ this_thorn = thornnode->data;
+ if(this_thorn->activates_thorns)
{
- new_thorn = this_thorn->activates_thorns[i];
- if (! CCTK_IsThornActive(new_thorn))
+ for(i = 0; this_thorn->activates_thorns[i]; i++)
{
- switch (Util_StringListAdd(new_thorns, new_thorn))
+ new_thorn = this_thorn->activates_thorns[i];
+ if (! CCTK_IsThornActive(new_thorn))
{
- case 0:
- /* Thorn already scheduled for activation */
- break;
- case 1:
- printf("Thorn %s requests automatic activation of %s\n",
- thorn, new_thorn);
- did_add_thorns = 1;
- break;
- default:
- CCTK_Warn(0, __LINE__, __FILE__, "Cactus", "Internal error");
+ switch (Util_StringListAdd(new_thorns, new_thorn))
+ {
+ case 0:
+ /* Thorn already scheduled for activation */
+ break;
+ case 1:
+ printf("Thorn %s requests automatic activation of %s\n",
+ thorn, new_thorn);
+ did_add_thorns = 1;
+ break;
+ default:
+ CCTK_Warn(0, __LINE__, __FILE__, "Cactus", "Internal error");
+ }
}
}
}