Fix potential off-by-one error when using hash fudging. It needs to

round up to 2/4 and not one less to guarantee that the adjusted hash
fits into array.
This commit is contained in:
joerg 2021-01-26 21:25:55 +00:00
parent 09fe26b20f
commit 63eec5d6ba
2 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nbperf-bdz.c,v 1.10 2021/01/07 16:03:08 joerg Exp $ */
/* $NetBSD: nbperf-bdz.c,v 1.11 2021/01/26 21:25:55 joerg Exp $ */
/*-
* Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
* All rights reserved.
@ -36,7 +36,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: nbperf-bdz.c,v 1.10 2021/01/07 16:03:08 joerg Exp $");
__RCSID("$NetBSD: nbperf-bdz.c,v 1.11 2021/01/26 21:25:55 joerg Exp $");
#include <err.h>
#include <inttypes.h>
@ -285,7 +285,7 @@ bpz_compute(struct nbperf *nbperf)
if (v < 10)
v = 10;
if (nbperf->allow_hash_fudging)
v |= 3;
v = (v + 3) & ~3;
graph3_setup(&state.graph, v, e);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nbperf-chm.c,v 1.4 2021/01/07 16:03:08 joerg Exp $ */
/* $NetBSD: nbperf-chm.c,v 1.5 2021/01/26 21:25:55 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
@ -35,7 +35,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: nbperf-chm.c,v 1.4 2021/01/07 16:03:08 joerg Exp $");
__RCSID("$NetBSD: nbperf-chm.c,v 1.5 2021/01/26 21:25:55 joerg Exp $");
#include <err.h>
#include <inttypes.h>
@ -262,12 +262,12 @@ chm_compute(struct nbperf *nbperf)
if (v < 10)
v = 10;
if (nbperf->allow_hash_fudging)
v |= 3;
v = (v + 3) & ~3;
#else
if (v == 2 * nbperf->n)
++v;
if (nbperf->allow_hash_fudging)
v |= 1;
v = (v + 1) & ~1;
#endif
state.g = calloc(sizeof(uint32_t), v);