From 7fa203018d02d8f2b71a6be1240c3963a63cab1c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 29 Dec 2020 19:34:55 -0800 Subject: [PATCH] hash: add casts-to-float to avoid clang-10 warnings * lib/hash.c (compute_bucket_size): Cast SIZE_MAX to float to avoid this warning from clang-10 (for use in grep): hash.c:501:11: error: implicit conversion from 'unsigned long' \ to 'float' changes value from 18446744073709551615 to \ 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion] if (SIZE_MAX <= new_candidate) (hash_insert_if_absent): Likewise. --- ChangeLog | 11 +++++++++++ lib/hash.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2af7a42c79..cc4e456655 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2020-12-29 Jim Meyering + + hash: add casts-to-float to avoid clang-10 warnings + * lib/hash.c (compute_bucket_size): Cast SIZE_MAX to float + to avoid this warning from clang-10 (for use in grep): + hash.c:501:11: error: implicit conversion from 'unsigned long' \ + to 'float' changes value from 18446744073709551615 to \ + 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion] + if (SIZE_MAX <= new_candidate) + (hash_insert_if_absent): Likewise. + 2020-12-29 Paul Eggert canonicalize: fix size overflow treatment diff --git a/lib/hash.c b/lib/hash.c index 2d64c82e59..e5ae96ce60 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -498,7 +498,7 @@ compute_bucket_size (size_t candidate, const Hash_tuning *tuning) if (!tuning->is_n_buckets) { float new_candidate = candidate / tuning->growth_threshold; - if (SIZE_MAX <= new_candidate) + if ((float) SIZE_MAX <= new_candidate) return 0; candidate = new_candidate; } @@ -961,7 +961,7 @@ hash_insert_if_absent (Hash_table *table, void const *entry, : (table->n_buckets * tuning->growth_factor * tuning->growth_threshold)); - if (SIZE_MAX <= candidate) + if ((float) SIZE_MAX <= candidate) return -1; /* If the rehash fails, arrange to return NULL. */ -- 2.39.5