[Freeciv-Dev] (PR#4788) range checks in BV macros
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch introduces assertions on the range of the input in the BV_***
macros. Probably a good thing IMO.
jason
Index: common/shared.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/shared.h,v
retrieving revision 1.114
diff -u -r1.114 shared.h
--- common/shared.h 2003/07/19 04:05:59 1.114
+++ common/shared.h 2003/08/08 04:20:50
@@ -120,12 +120,16 @@
#define _BV_BYTES(bits) ((((bits) - 1) / 8) + 1)
#define _BV_BYTE_INDEX(bits) ((bits) / 8)
#define _BV_BITMASK(bit) (1u << ((bit) & 0x7))
+#define _BV_ASSERT(bv, bit) assert((bit) >= 0 && (bit) < sizeof((bv).vec) * 8)
#define BV_ISSET(bv, bit) \
- (((bv).vec[_BV_BYTE_INDEX(bit)] & _BV_BITMASK(bit)) != 0)
+ (_BV_ASSERT(bv, bit), \
+ ((bv).vec[_BV_BYTE_INDEX(bit)] & _BV_BITMASK(bit)) != 0)
#define BV_SET(bv, bit) \
- do { (bv).vec[_BV_BYTE_INDEX(bit)] |= _BV_BITMASK(bit); } while(FALSE)
+ do { _BV_ASSERT(bv, bit); \
+ (bv).vec[_BV_BYTE_INDEX(bit)] |= _BV_BITMASK(bit); } while(FALSE)
#define BV_CLR(bv, bit) \
- do { (bv).vec[_BV_BYTE_INDEX(bit)] &= ~_BV_BITMASK(bit); } while(FALSE)
+ do { _BV_ASSERT(bv, bit); \
+ (bv).vec[_BV_BYTE_INDEX(bit)] &= ~_BV_BITMASK(bit); } while(FALSE)
#define BV_CLR_ALL(bv) \
do { memset((bv).vec, 0, sizeof((bv).vec)); } while(FALSE)
bool bv_check_mask(unsigned char *vec1, unsigned char *vec2, size_t size1,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#4788) range checks in BV macros,
Jason Short <=
|
|