diff options
author | Jim Meyering <jim@meyering.net> | 2003-08-18 09:44:49 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-08-18 09:44:49 +0000 |
commit | b1b4af8047b2d6c2b2ea0d552969e25f872da675 (patch) | |
tree | ee8166cbc3f75e901def92c7c94473473d360165 /lib/hash.c | |
parent | 84a9ab5a07427ab8322424cd0c401e847326e7e2 (diff) | |
download | coreutils-b1b4af8047b2d6c2b2ea0d552969e25f872da675.tar.xz |
Sync with gnulib.
Diffstat (limited to 'lib/hash.c')
-rw-r--r-- | lib/hash.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/hash.c b/lib/hash.c index 0bbe09596..7373a011c 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -34,7 +34,6 @@ #include <limits.h> #include <stdbool.h> #include <stdio.h> -#include <assert.h> #ifndef HAVE_DECL_FREE "this configure-time declaration test was not run" @@ -264,7 +263,8 @@ hash_lookup (const Hash_table *table, const void *entry) = table->bucket + table->hasher (entry, table->n_buckets); struct hash_entry *cursor; - assert (bucket < table->bucket_limit); + if (! (bucket < table->bucket_limit)) + abort (); if (bucket->data == NULL) return NULL; @@ -293,12 +293,11 @@ hash_get_first (const Hash_table *table) if (table->n_entries == 0) return NULL; - for (bucket = table->bucket; bucket < table->bucket_limit; bucket++) - if (bucket->data) + for (bucket = table->bucket; ; bucket++) + if (! (bucket < table->bucket_limit)) + abort (); + else if (bucket->data) return bucket->data; - - assert (0); - return NULL; } /* Return the user data for the entry following ENTRY, where ENTRY has been @@ -312,7 +311,8 @@ hash_get_next (const Hash_table *table, const void *entry) = table->bucket + table->hasher (entry, table->n_buckets); struct hash_entry *cursor; - assert (bucket < table->bucket_limit); + if (! (bucket < table->bucket_limit)) + abort (); /* Find next entry in the same bucket. */ for (cursor = bucket; cursor; cursor = cursor->next) @@ -752,7 +752,9 @@ hash_find_entry (Hash_table *table, const void *entry, = table->bucket + table->hasher (entry, table->n_buckets); struct hash_entry *cursor; - assert (bucket < table->bucket_limit); + if (! (bucket < table->bucket_limit)) + abort (); + *bucket_head = bucket; /* Test for empty bucket. */ @@ -846,7 +848,9 @@ hash_rehash (Hash_table *table, unsigned candidate) = (new_table->bucket + new_table->hasher (data, new_table->n_buckets)); - assert (new_bucket < new_table->bucket_limit); + if (! (new_bucket < new_table->bucket_limit)) + abort (); + next = cursor->next; if (new_bucket->data) @@ -910,7 +914,9 @@ hash_insert (Hash_table *table, const void *entry) void *data; struct hash_entry *bucket; - assert (entry); /* cannot insert a NULL entry */ + /* The caller cannot insert a NULL entry. */ + if (! entry) + abort (); /* If there's a matching entry already in the table, return that. */ if ((data = hash_find_entry (table, entry, &bucket, false)) != NULL) |