diff options
author | schnetter <schnetter@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e> | 2005-12-18 21:40:52 +0000 |
---|---|---|
committer | schnetter <schnetter@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e> | 2005-12-18 21:40:52 +0000 |
commit | 5a79ae9405bfc2b531b9a7c36855eb01f29b9cd2 (patch) | |
tree | 3fc8615fa689ab5d33083e709193dc9601e9f987 /src/MaskUtils.c | |
parent | c9e312546650f5b2cb9590e92e7076a430fac664 (diff) |
Do not use the topmost 2 bits in a CCTK_INT, since this leads to
undefined behaviour in C. We could use more clever code and then use
the second-topmost bit as well, omitting only 1 bit.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/SpaceMask/trunk@54 a491c6a4-70bf-4b89-8b36-d6c0cb1f094e
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) { |