diff --git a/src/bmz.c b/src/bmz.c index 062677c..d2d90d7 100644 --- a/src/bmz.c +++ b/src/bmz.c @@ -530,7 +530,7 @@ cmph_uint32 bmz_search(cmph_t *mphf, const char *key, cmph_uint32 keylen) cmph_uint32 h1 = hash(bmz->hashes[0], key, keylen) % bmz->n; cmph_uint32 h2 = hash(bmz->hashes[1], key, keylen) % bmz->n; DEBUGP("key: %.*s h1: %u h2: %u\n", keylen, key, h1, h2); - if (h1 == h2 && ++h2 > bmz->n) h2 = 0; + if (h1 == h2 && ++h2 >= bmz->n) h2 = 0; DEBUGP("key: %.*s g[h1]: %u g[h2]: %u edges: %u\n", keylen, key, bmz->g[h1], bmz->g[h2], bmz->m); return bmz->g[h1] + bmz->g[h2]; } @@ -620,6 +620,6 @@ cmph_uint32 bmz_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; - if (h1 == h2 && ++h2 > n) h2 = 0; + if (h1 == h2 && ++h2 >= n) h2 = 0; return (g_ptr[h1] + g_ptr[h2]); } diff --git a/src/cmph.c b/src/cmph.c index f460dd0..96e6a3e 100644 --- a/src/cmph.c +++ b/src/cmph.c @@ -157,11 +157,11 @@ static cmph_uint32 count_nlfile_keys(FILE *fd) { char buf[BUFSIZ]; ptr = fgets(buf, BUFSIZ, fd); - if (feof(fd)) break; - if (ferror(fd) || ptr == NULL) { - perror("Error reading input file"); - return 0; - } + if (feof(fd)) break; + if (ferror(fd) || ptr == NULL) { + perror("Error reading input file"); + return 0; + } if (buf[strlen(buf) - 1] != '\n') continue; ++count; }