From 17ed72b8d2bf083ad5a0d32007e76879b507b6fe Mon Sep 17 00:00:00 2001 From: davi Date: Fri, 23 Sep 2005 20:57:42 +0000 Subject: [PATCH] Fixed small main.cc bug when -m parameter was in use. --- src/main.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 112fdc7..8a7f977 100644 --- a/src/main.c +++ b/src/main.c @@ -187,6 +187,7 @@ int main(int argc, char **argv) if (seed == UINT_MAX) seed = (cmph_uint32)time(NULL); srand(seed); + int ret = 0; if (mphf_file == NULL) { mphf_file = (char *)malloc(strlen(keys_file) + 5); @@ -255,6 +256,7 @@ int main(int argc, char **argv) free(mphf_file); return -1; } + cmph_uint32 siz = cmph_size(mphf); hashtable = (cmph_uint8*)malloc(source->nkeys*sizeof(cmph_uint8)); memset(hashtable, 0, source->nkeys); //check all keys @@ -265,10 +267,16 @@ int main(int argc, char **argv) cmph_uint32 buflen = 0; source->read(source->data, &buf, &buflen); h = cmph_search(mphf, buf, buflen); - assert(h < source->nkeys); - if(hashtable[h])fprintf(stderr, "collision: %u\n",h); - assert(hashtable[h]==0); - hashtable[h] = 1; + if (!(h < siz)) + { + fprintf(stderr, "Unknown key %*s in the input.\n", buflen, buf); + ret = 1; + } else if(hashtable[h]) + { + fprintf(stderr, "Duplicated or unknown key %*s in the input\n", buflen, buf); + ret = 1; + } else hashtable[h] = 1; + if (verbosity) { printf("%s -> %u\n", buf, h); @@ -282,5 +290,5 @@ int main(int argc, char **argv) free(mphf_file); free(tmp_dir); free(source); - return 0; + return ret; }