[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] proposed fixes for hash and hash-pjw modules
From: |
Jim Meyering |
Subject: |
Re: [Bug-gnulib] proposed fixes for hash and hash-pjw modules |
Date: |
Sat, 25 Oct 2003 17:35:26 +0200 |
Paul Eggert <address@hidden> wrote:
> I found many address-calculation bugs in the hash module of gnulib.
> Much of it was due to its use of unsigned int rather than size_t, so I
> propose that we change its interfaces to use size_t rather than
> unsigned int. There are a few more-subtle bugs (some involving
> potential rounding errors in the floating-point calculations, urk!).
>
> Here is a proposed patch.
>
> 2003-10-25 Paul Eggert <address@hidden>
>
> Fix several address-calculation bugs, plus some minor code cleanup.
> While we're at it, modify hash-pjw to use the algorithm that
> Bruno Haible recommends.
>
> * hash.h: Include <stdbool.h>, for bool.
> * hash.c: Don't include <stdbool.h>, since hash.h does it now.
> * hash.h (Hash_hasher, hash_get_n_buckets, hash_get_n_buckets_used,
> hash_get_n_entries, hash_get_max_bucket_length,
> hash_get_entries, hash_do_for_each, hash_string, hash_initialize,
> hash_rehash): Use size_t rather than unsigned.
> * hash.c (struct hash_table, hash_get_n_buckets,
> hash_get_n_buckets_used, hash_get_n_entries,
> hash_get_max_bucket_length, hash_table_ok, hash_print_statistics,
> hash_get_entries, hash_do_for_each, hash_string, is_prime,
> next_prime, hash_initialize, hash_rehash, hash_delete, hash_print):
> Likewise.
> (SIZE_MAX): Define if not defined.
> (hash_get_max_bucket_length, hash_table_ok, hash_lookup,
> hash_get_first, hash_get_next, hash_get_entries, hash_do_for_each,
> hash_print):
> Use const * when possible.
> (hash_string): Use (unsigned char) *P rather than *(unsigned char *) P.
> (check_tuning): Fix bug: if tuning parameters were very close to
> 0 or 1, rounding errors could have caused subscript violations.
> (hash_initialize, allocate_entry, hash_print): Remove unnecessary cast.
> (hash_initialize): Add 'fail:' label
> to free table and return NULL, and use it to simplify code.
> Use calloc rather than clearing the storage ourself.
> (hash_initialize, hash_rehash): Check for arithmetic overflow in
> buffer size calculations.
> * hash-pjw.h (hash_pjw): Use size_t, not unsigned.
> * hash-pjw.c (hash_pjw): Likewise.
> Switch to method described by Bruno Haible.
> Include <limits.h>, for CHAR_BIT.
> (SIZE_BITS): New macro.
Thanks!
I've applied all of that and have made the corresponding
adjustments in coreutils.