bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] hash: silence spurious clang warning


From: Eric Blake
Subject: Re: [PATCH] hash: silence spurious clang warning
Date: Tue, 31 Aug 2010 08:29:28 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100806 Fedora/3.1.2-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.2

On 08/31/2010 08:11 AM, Eric Blake wrote:
On 08/31/2010 02:10 AM, Jim Meyering wrote:
Eric, I've listed you as an author, so will wait for your ACK.

From 5bcff7b85b7b88fa4809ad874a1203e27abed085 Mon Sep 17 00:00:00 2001
From: Eric Blake<address@hidden>
Date: Tue, 31 Aug 2010 10:06:16 +0200
Subject: [PATCH] hash: factor, and guard against misbehaving hasher
function

* lib/hash.c (safe_hasher): New function, to encapsulate the checking
of table->hasher's return value. Also protect against a hash value
so large that adding it to table->bucket would result in a NULL pointer.
(hash_lookup, hash_get_next, hash_find_entry): Use it in place of
open-coded check-and-abort.

ACK from me.

Actually, you missed one function.  I'm squashing this in, then pushing.

diff --git i/ChangeLog w/ChangeLog
index ef3adf1..9ed2f79 100644
--- i/ChangeLog
+++ w/ChangeLog
@@ -1,12 +1,12 @@
 2010-08-31  Eric Blake  <address@hidden>
-           Jim Meyering  <address@hidden>
+       and Jim Meyering  <address@hidden>

        hash: factor, and guard against misbehaving hasher function
        * lib/hash.c (safe_hasher): New function, to encapsulate the checking
        of table->hasher's return value.  Also protect against a hash value
        so large that adding it to table->bucket would result in a NULL pointer.
-       (hash_lookup, hash_get_next, hash_find_entry): Use it in place of
-       open-coded check-and-abort.
+       (hash_lookup, hash_get_next, hash_find_entry, transfer_entries):
+       Use it in place of open-coded check-and-abort.

 2010-08-30  Bruno Haible  <address@hidden>

diff --git i/lib/hash.c w/lib/hash.c
index 30a10b1..a4a2420 100644
--- i/lib/hash.c
+++ w/lib/hash.c
@@ -877,10 +877,7 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool 
safe)
         for (cursor = bucket->next; cursor; cursor = next)
           {
             data = cursor->data;
-            new_bucket = (dst->bucket + dst->hasher (data, dst->n_buckets));
-
-            if (! (new_bucket < dst->bucket_limit))
-              abort ();
+            new_bucket = safe_hasher (dst, data);

             next = cursor->next;

@@ -907,10 +904,7 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool 
safe)
         bucket->next = NULL;
         if (safe)
           continue;
-        new_bucket = (dst->bucket + dst->hasher (data, dst->n_buckets));
-
-        if (! (new_bucket < dst->bucket_limit))
-          abort ();
+        new_bucket = safe_hasher (dst, data);

         if (new_bucket->data)
           {


--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]