Navigation Menu

Skip to content

Commit

Permalink
* Fix subtle bug in linkhash where lookup could hang after all slots
Browse files Browse the repository at this point in the history
    were filled then successively freed.
    Spotted by Jean-Marc Naud, j dash m at newtraxtech dot com


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@54 327403b1-1117-474d-bef2-5cb71233fd97
  • Loading branch information
michaeljclark committed Aug 27, 2009
1 parent 126ad95 commit f5dd43a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
0.10
* Fix subtle bug in linkhash where lookup could hang after all slots
were filled then successively freed.
Spotted by Jean-Marc Naud, j dash m at newtraxtech dot com
* Make json_object_from_file take const char *filename
Spotted by Vikram Raj V, vsagar at attinteractive dot com
* Add handling of surrogate pairs (json_tokener.c, test4.c, Makefile.am) * Add handling of surrogate pairs (json_tokener.c, test4.c, Makefile.am)
Brent Miller, bdmiller at yahoo dash inc dot com Brent Miller, bdmiller at yahoo dash inc dot com
* Correction to comment describing printbuf_memappend in printbuf.h * Correction to comment describing printbuf_memappend in printbuf.h
Expand Down
4 changes: 3 additions & 1 deletion linkhash.c
Expand Up @@ -158,13 +158,15 @@ struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k)
{ {
unsigned long h = t->hash_fn(k); unsigned long h = t->hash_fn(k);
unsigned long n = h % t->size; unsigned long n = h % t->size;
int count = 0;


t->lookups++; t->lookups++;
while( 1 ) { while( count < t->size ) {
if(t->table[n].k == LH_EMPTY) return NULL; if(t->table[n].k == LH_EMPTY) return NULL;
if(t->table[n].k != LH_FREED && if(t->table[n].k != LH_FREED &&
t->equal_fn(t->table[n].k, k)) return &t->table[n]; t->equal_fn(t->table[n].k, k)) return &t->table[n];
if(++n == t->size) n = 0; if(++n == t->size) n = 0;
count++;
} }
return NULL; return NULL;
} }
Expand Down

0 comments on commit f5dd43a

Please sign in to comment.