* lib/hash.c (hash_get_next): Aid clang analysis. Signed-off-by: Eric Blake <[email protected]> ---
Jim, should we apply this? As far as I can tell, this is an example of a shortfall in clang 2.7, as shipped in Fedora 13. Clang assumed that the for loop at line 310 is skipped because cursor is NULL, which implies bucket is NULL, which implies that line 316 bucket->data is a dereference near NULL. But this is invalid, because bucket was explicitly initialized to table->bucket (non-NULL) plus some offset, at line 302. Adding the extra condition before the abort() is enough to get clang's invalid assumption out of the way. ChangeLog | 3 +++ lib/hash.c | 2 +- 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index fec5dc9..246d144 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2010-08-30 Eric Blake <[email protected]> + hash: silence spurious clang warning + * lib/hash.c (hash_get_next): Aid clang analysis. + tests: silence clang warning * tests/test-malloca.c (do_allocation): Avoid dead store. diff --git a/lib/hash.c b/lib/hash.c index 15630be..e2727b9 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -303,7 +303,7 @@ hash_get_next (const Hash_table *table, const void *entry) = table->bucket + table->hasher (entry, table->n_buckets); struct hash_entry const *cursor; - if (! (bucket < table->bucket_limit)) + if (! (bucket && bucket < table->bucket_limit)) abort (); /* Find next entry in the same bucket. */ -- 1.7.2.2
