mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Be more careful with type of left operand of <<
On a 32-bit system, evaluating 1<<31 causes undefined behaviour because 1 is signed and so it produces signed overflow. UBSan has spotted a couple of occasions where this happens in Puzzles, so in each case I've converted the left operand to the unsigned result type we actually want.
This commit is contained in:
4
cube.c
4
cube.c
@ -202,8 +202,8 @@ struct game_grid {
|
||||
};
|
||||
|
||||
#define SET_SQUARE(state, i, val) \
|
||||
((state)->bluemask[(i)/32] &= ~(1 << ((i)%32)), \
|
||||
(state)->bluemask[(i)/32] |= ((!!val) << ((i)%32)))
|
||||
((state)->bluemask[(i)/32] &= ~(1UL << ((i)%32)), \
|
||||
(state)->bluemask[(i)/32] |= ((unsigned long)(!!val) << ((i)%32)))
|
||||
#define GET_SQUARE(state, i) \
|
||||
(((state)->bluemask[(i)/32] >> ((i)%32)) & 1)
|
||||
|
||||
|
Reference in New Issue
Block a user