mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 05:03:40 +00:00
lib: remove overflow arithmetic from hash stats
Signed values get converted to unsigned for addition, so when the value to adjust a stats variable for hash tables was negative this resulted in overflow arithmetic, which we generally don't want. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
This commit is contained in:
parent
e9faf4be72
commit
e6464fdc18
15
lib/hash.c
15
lib/hash.c
@ -77,9 +77,20 @@ void *hash_alloc_intern(void *arg)
|
|||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ssq = ssq + (new^2 - old^2)
|
||||||
|
* = ssq + ((new + old) * (new - old))
|
||||||
|
*/
|
||||||
#define hash_update_ssq(hz, old, new) \
|
#define hash_update_ssq(hz, old, new) \
|
||||||
atomic_fetch_add_explicit(&hz->stats.ssq, (new + old) * (new - old), \
|
do { \
|
||||||
memory_order_relaxed);
|
int _adjust = (new + old) * (new - old); \
|
||||||
|
if (_adjust < 0) \
|
||||||
|
atomic_fetch_sub_explicit(&hz->stats.ssq, -_adjust, \
|
||||||
|
memory_order_relaxed); \
|
||||||
|
else \
|
||||||
|
atomic_fetch_add_explicit(&hz->stats.ssq, _adjust, \
|
||||||
|
memory_order_relaxed); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/* Expand hash if the chain length exceeds the threshold. */
|
/* Expand hash if the chain length exceeds the threshold. */
|
||||||
static void hash_expand(struct hash *hash)
|
static void hash_expand(struct hash *hash)
|
||||||
|
Loading…
Reference in New Issue
Block a user