From fb6ded3f593d5084e488093fb8ac4d133a27a659 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 6 Nov 2012 04:17:46 +0000 Subject: bad use of assignment within ABS() caused SMHASH_NEXT macro to step the offset twice in some cases. --- source/blender/blenlib/intern/smallhash.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/smallhash.c b/source/blender/blenlib/intern/smallhash.c index 92125c6e988..64bb503fa3c 100644 --- a/source/blender/blenlib/intern/smallhash.c +++ b/source/blender/blenlib/intern/smallhash.c @@ -43,8 +43,22 @@ #define SMHASH_CELL_UNUSED ((void *)0x7FFFFFFF) #define SMHASH_CELL_FREE ((void *)0x7FFFFFFD) -#define SMHASH_NONZERO(n) ((n) + !(n)) -#define SMHASH_NEXT(h, hoff) ABS(((h) + ((hoff = SMHASH_NONZERO(hoff * 2) + 1), hoff))) +BLI_INLINE int smhash_nonzero(const int n) +{ + return n + !n; +} + +BLI_INLINE int smhash_abs_i(const int n) +{ + return (n > 0) ? n : -n; +} + +/* typically this re-assigns 'h' */ +#define SMHASH_NEXT(h, hoff) ( \ + CHECK_TYPE_INLINE(&(h), int), \ + CHECK_TYPE_INLINE(&(hoff), int), \ + smhash_abs_i((h) + (((hoff) = smhash_nonzero((hoff) * 2) + 1), (hoff))) \ + ) extern unsigned int hashsizes[]; -- cgit v1.2.3