summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2001-04-21 17:09:46 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2001-04-21 17:09:46 +0000
commiteaccd831d72d12db04db73660d313c3bec6538cd (patch)
tree5a71d862f8cf58cca38eaf5ddc63ee70a13d6027
parent9be4bce5946ab62b1bdd330463d1de907cf5c598 (diff)
Check for invalid group index in CCTK_GroupTypeI().
Fixed nasty warning about discarding const qualifier from pointer target type. git-svn-id: http://svn.cactuscode.org/flesh/trunk@2132 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r--src/main/Groups.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/main/Groups.c b/src/main/Groups.c
index 9a59111a..f541deaf 100644
--- a/src/main/Groups.c
+++ b/src/main/Groups.c
@@ -1,5 +1,5 @@
/*@@
- @file Groups.c
+ @file Groups.c
@date Mon Feb 1 12:16:28 1999
@author Tom Goodale
@desc
@@ -1167,7 +1167,7 @@ int CCTK_GroupTypeFromVarI (int var)
@@*/
int CCTK_GroupTypeI (int group)
{
- return groups[group].gtype;
+ return ((0 <= group && group < n_groups) ? groups[group].gtype : -1);
}
@@ -1528,10 +1528,14 @@ int CCTK_TraverseString (const char *parsestring,
int retval;
char *before;
char *after;
- char *splitstring;
char *optstring;
int idx, first, last;
int selected_all;
+ union
+ {
+ char *string;
+ const char *const_string;
+ } splitstring;
if (callback == NULL)
@@ -1542,15 +1546,17 @@ int CCTK_TraverseString (const char *parsestring,
retval = 0;
- splitstring = (char *) parsestring;
+ /* avoid the compiler warning "cast discards `const' from pointer
+ target type" */
+ splitstring.const_string = parsestring;
after = NULL;
- while (splitstring && *splitstring)
+ while (splitstring.string && *splitstring.string)
{
- if (Util_SplitString (&before, &after, splitstring, " "))
+ if (Util_SplitString (&before, &after, splitstring.string, " "))
{
- before = splitstring;
+ before = splitstring.string;
if (after)
{
free (after);
@@ -1559,7 +1565,7 @@ int CCTK_TraverseString (const char *parsestring,
}
#ifdef DEBUG_GROUPS
- printf (" String is '%s'\n", splitstring);
+ printf (" String is '%s'\n", splitstring.string);
printf (" Split is '%s' and '%s'\n", before, after);
#endif
@@ -1641,15 +1647,15 @@ int CCTK_TraverseString (const char *parsestring,
}
}
- if (before != splitstring)
+ if (before != splitstring.string)
{
free (before);
}
- if (splitstring != parsestring)
+ if (splitstring.string != parsestring)
{
- free (splitstring);
+ free (splitstring.string);
}
- splitstring = after;
+ splitstring.string = after;
}
if (after)