diff options
Diffstat (limited to 'src/MaskUtils.c')
-rw-r--r-- | src/MaskUtils.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/MaskUtils.c b/src/MaskUtils.c index 2e9bf8e..1cb2eea 100644 --- a/src/MaskUtils.c +++ b/src/MaskUtils.c @@ -109,7 +109,11 @@ SpaceMask_get_free_bits(int nbits) n=1; new_bits = 0; j = 0; - for (i=0; i < (int) sizeof(CCTK_INT)*8 && j<nbits; ++i) + /* Do not use the 2 top bits. Signed integer datatypes in C do not + have the overflow semantics that many people expect. With care, + we could use the second topmost bit as well, but this doesn't + seem important at the moment. */ + for (i=0; i < (int) sizeof(CCTK_INT)*8-2 && j<nbits; ++i) { if (!(n & used_bits)) { @@ -159,7 +163,11 @@ SpaceMask_determine_state_mask(CCTK_INT allocated_bits, int nstates) n=1; bit=1; - for (i=0; i < (int) sizeof(CCTK_INT)*8; ++i) + /* Do not use the 2 top bits. Signed integer datatypes in C do not + have the overflow semantics that many people expect. With care, + we could use the second topmost bit as well, but this doesn't + seem important at the moment. */ + for (i=0; i < (int) sizeof(CCTK_INT)*8-2; ++i) { if (n & allocated_bits) { |