diff options
author | schnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2004-04-04 21:37:08 +0000 |
---|---|---|
committer | schnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2004-04-04 21:37:08 +0000 |
commit | 5a1be2ea19469429e3dfcff8c32b1ca9f3e1dfae (patch) | |
tree | d89c63e39657dbee7d47c18525dfc4b57aab9706 /src/main/Groups.c | |
parent | 67c7e5c644398f5bfbd6c6f5453abced420bbd31 (diff) |
Check malloc return values more carefully: malloc(0)==0 is not an
error.
CCTKi_Extract: Ensure dimension>=0, and do not access the array when
dimension==0.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@3644 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/Groups.c')
-rw-r--r-- | src/main/Groups.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/main/Groups.c b/src/main/Groups.c index acb04d16..6ba3c263 100644 --- a/src/main/Groups.c +++ b/src/main/Groups.c @@ -2443,10 +2443,11 @@ static cGroupDefinition *CCTKi_SetupGroup (const char *implementation, temp_int = (int *) realloc (group_of_variable, (total_variables+n_variables) * sizeof (int)); - if (groups[n_groups].implementation && - groups[n_groups].name && - groups[n_groups].variables && - temp_int) + if ((n_variables==0 || (groups[n_groups].implementation && + groups[n_groups].name && + groups[n_groups].variables)) + && + ((total_variables+n_variables==0) || (temp_int))) { /* Fill in the data structures. */ group_of_variable = temp_int; @@ -2539,6 +2540,11 @@ static CCTK_INT **CCTKi_ExtractSize (int dimension, CCTK_INT **size_array; + if (dimension < 0) + { + CCTK_Warn (0, __LINE__, __FILE__, "Cactus","Illegal dimension specified"); + } + if (strlen (sizestring)) { next_comma = sizestring; @@ -2547,29 +2553,32 @@ static CCTK_INT **CCTKi_ExtractSize (int dimension, if (size_array) { - size_array[0] = (CCTK_INT *) malloc (dimension * sizeof (CCTK_INT)); - - for (dim = 1; dim < dimension; dim++) + if (dimension > 0) { - size_array[dim] = size_array[0] + dim; - } - - for (dim = 0; dim < dimension; dim++) - { - /* find the comma as a delimiter for different dimension sizes */ - last_comma = next_comma[0] == ',' ? next_comma+1 : next_comma; - next_comma = strstr (last_comma, ","); - - /* copy dimension size token into a work string buffer */ - tmp = strdup (last_comma); - if (next_comma) + size_array[0] = (CCTK_INT *) malloc (dimension * sizeof (CCTK_INT)); + + for (dim = 1; dim < dimension; dim++) { - tmp[next_comma-last_comma] = '\0'; + size_array[dim] = size_array[0] + dim; + } + + for (dim = 0; dim < dimension; dim++) + { + /* find the comma as a delimiter for different dimension sizes */ + last_comma = next_comma[0] == ',' ? next_comma+1 : next_comma; + next_comma = strstr (last_comma, ","); + + /* copy dimension size token into a work string buffer */ + tmp = strdup (last_comma); + if (next_comma) + { + tmp[next_comma-last_comma] = '\0'; + } + + *size_array[dim] = CCTKi_ParamExpressionToInt (tmp, this_thorn); + + free (tmp); } - - *size_array[dim] = CCTKi_ParamExpressionToInt (tmp, this_thorn); - - free (tmp); } } } |