=================================================================== RCS file: /cvs/mandoc/compat_ohash.c,v retrieving revision 1.3 retrieving revision 1.7 diff -u -p -r1.3 -r1.7 --- mandoc/compat_ohash.c 2014/06/20 02:10:05 1.3 +++ mandoc/compat_ohash.c 2020/06/15 01:37:15 1.7 @@ -1,15 +1,6 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +/* $Id: compat_ohash.c,v 1.7 2020/06/15 01:37:15 schwarze Exp $ */ +/* $OpenBSD: compat_ohash.c,v 1.7 2020/06/15 01:37:15 schwarze Exp $ */ -#ifdef HAVE_OHASH - -int dummy; - -#else - -/* $OpenBSD: compat_ohash.c,v 1.3 2014/06/20 02:10:05 schwarze Exp $ */ - /* Copyright (c) 1999, 2004 Marc Espie * * Permission to use, copy, modify, and distribute this software for any @@ -24,11 +15,14 @@ int dummy; * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "config.h" +#include #include #include #include #include +#include #include "compat_ohash.h" struct _ohash_record { @@ -69,8 +63,7 @@ ohash_create_entry(struct ohash_info *i, const char *s void ohash_delete(struct ohash *h) { - (h->info.hfree)(h->t, sizeof(struct _ohash_record) * h->size, - h->info.data); + (h->info.free)(h->t, h->info.data); #ifndef NDEBUG h->t = NULL; #endif @@ -80,13 +73,17 @@ static void ohash_resize(struct ohash *h) { struct _ohash_record *n; - unsigned int ns, j; + size_t ns; + unsigned int j; unsigned int i, incr; - if (4 * h->deleted < h->total) - ns = h->size << 1; - else if (3 * h->deleted > 2 * h->total) - ns = h->size >> 1; + if (4 * h->deleted < h->total) { + if (h->size >= (UINT_MAX >> 1U)) + ns = UINT_MAX; + else + ns = h->size << 1U; + } else if (3 * h->deleted > 2 * h->total) + ns = h->size >> 1U; else ns = h->size; if (ns < MINSIZE) @@ -95,7 +92,8 @@ ohash_resize(struct ohash *h) STAT_HASH_EXPAND++; STAT_HASH_SIZE += ns - h->size; #endif - n = (h->info.halloc)(sizeof(struct _ohash_record) * ns, h->info.data); + + n = (h->info.calloc)(ns, sizeof(struct _ohash_record), h->info.data); if (!n) return; @@ -112,8 +110,7 @@ ohash_resize(struct ohash *h) n[i].p = h->t[j].p; } } - (h->info.hfree)(h->t, sizeof(struct _ohash_record) * h->size, - h->info.data); + (h->info.free)(h->t, h->info.data); h->t = n; h->size = ns; h->total -= h->deleted; @@ -199,12 +196,12 @@ ohash_init(struct ohash *h, unsigned int size, struct #endif /* Copy info so that caller may free it. */ h->info.key_offset = info->key_offset; - h->info.halloc = info->halloc; - h->info.hfree = info->hfree; + h->info.calloc = info->calloc; + h->info.free = info->free; h->info.alloc = info->alloc; h->info.data = info->data; - h->t = (h->info.halloc)(sizeof(struct _ohash_record) * h->size, - h->info.data); + h->t = (h->info.calloc)(h->size, sizeof(struct _ohash_record), + h->info.data); h->total = h->deleted = 0; } @@ -331,5 +328,3 @@ ohash_qlookupi(struct ohash *h, const char *s, const c hv = ohash_interval(s, e); return ohash_lookup_interval(h, s, *e, hv); } - -#endif /*!HAVE_OHASH*/