diff options
Diffstat (limited to 'src/MaskUtils.c')
-rw-r--r-- | src/MaskUtils.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/MaskUtils.c b/src/MaskUtils.c index 29a280a..0f51d4b 100644 --- a/src/MaskUtils.c +++ b/src/MaskUtils.c @@ -120,7 +120,10 @@ SpaceMask_get_free_bits(int nbits) } if (j<nbits) - CCTK_WARN (0, "Cannot allocate mask: Not enough free bits."); + { + CCTK_WARN (1, "Cannot allocate mask: Not enough free bits."); + return 0; + } return new_bits; } @@ -216,6 +219,10 @@ SpaceMask_setup_new_type(CCTK_INT new_bits, const char* type_name, int j; new_type = (SpaceMask_Type*) malloc (sizeof(SpaceMask_Type)); + + if (new_type == NULL) + return NULL; + new_type->bitmask = new_bits; new_type->nstates = nstates; new_type->name = type_name; @@ -288,10 +295,16 @@ SpaceMask_RegisterType(const char* type_name, int nstates, bit_nbr = SpaceMask_get_bit_nbr(nstates); new_bits = SpaceMask_get_free_bits(bit_nbr); + + if (new_bits == 0) + return -1; + state_mask = SpaceMask_determine_state_mask(new_bits, nstates); new_type = SpaceMask_setup_new_type(new_bits, type_name, nstates, state_list, state_mask); + if (new_type == NULL) + return -1; SpaceMask_append_type_to_registry (new_type); @@ -348,6 +361,10 @@ SpaceMask_AppendStatesToType(const char* type_name, int nstates, SpaceMask_get_bit_nbr(old_type->nstates); new_bits = SpaceMask_get_free_bits(new_bit_nbr); + + if (new_bits == 0) + return -1; + allocated_bits = old_type->bitmask | new_bits; state_mask = SpaceMask_determine_state_mask(allocated_bits, total_nstates); @@ -362,6 +379,9 @@ SpaceMask_AppendStatesToType(const char* type_name, int nstates, new_type = SpaceMask_setup_new_type(allocated_bits, type_name, total_nstates, new_state_list, state_mask); + if (new_type == NULL) + return -1; + free(old_type); spacemask_registry->type_list[old_type_idx] = new_type; |