X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=selector.c;h=b849e65b7a5e5e2ff4adce999cc4a71776103335;hb=1c1c34b6adc7cf03bf97470ad1180fd61911b4b3;hp=803d3c978bd222ad6223b83b9360726005895cc5;hpb=285851f00df3657d63944776a43054ef68420723;p=selector.git diff --git a/selector.c b/selector.c index 803d3c9..b849e65 100644 --- a/selector.c +++ b/selector.c @@ -252,7 +252,7 @@ int add_and_get_previous_index(struct hash_table_t *hash_table, const char *new_string, int new_index, char **strings) { - unsigned int code = 0; + unsigned int code = 0, start; int k; /* This is my recipe. I checked, it seems to work (as long as @@ -264,6 +264,7 @@ int add_and_get_previous_index(struct hash_table_t *hash_table, } code = code % hash_table->size; + start = code; while(hash_table->entries[code] >= 0) { /* There is a string with that code */ @@ -278,6 +279,12 @@ int add_and_get_previous_index(struct hash_table_t *hash_table, /* This collision was not the same string, let's move to the next in the table */ code = (code + 1) % hash_table->size; + /* We came back to our original code, which means that the table + is full */ + if(code == start) { + printf("Full hash table (that should not happen)\n"); + exit(EXIT_FAILURE); + } } /* This string was not already in there, store the index in the @@ -980,14 +987,14 @@ int main(int argc, char **argv) { } } - if(show_help || error) { - if(error) { - usage(stderr); - exit(EXIT_FAILURE); - } else { - usage(stdout); - exit(EXIT_SUCCESS); - } + if(error) { + usage(stderr); + exit(EXIT_FAILURE); + } + + if(show_help) { + usage(stdout); + exit(EXIT_SUCCESS); } lines = safe_malloc(nb_lines_max * sizeof(char *));