From: Vsevolod Stakhov Date: Fri, 19 Dec 2014 10:55:06 +0000 (+0000) Subject: Resize hashes array properly. X-Git-Tag: 0.8.0~71 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a13bc71723ef269d7dcee56416a5f42cd8ee8a72;p=rspamd.git Resize hashes array properly. --- diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c index 6d33c7f26..9421c1529 100644 --- a/src/libutil/shingles.c +++ b/src/libutil/shingles.c @@ -69,7 +69,7 @@ rspamd_shingles_generate (GArray *input, /* Init hashes pipes and keys */ for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) { hashes[i] = g_array_sized_new (FALSE, FALSE, sizeof (guint64), - SHINGLES_WINDOW * 2); + input->len + SHINGLES_WINDOW); /* * To generate a set of hashes we just apply sha256 to the * initial key as many times as many hashes are required and @@ -80,7 +80,7 @@ rspamd_shingles_generate (GArray *input, blake2b_final (&bs, shabuf, shalen); for (j = 0; j < 16; j ++) { - out_key[j] = shabuf[j] ^ shabuf[sizeof(shabuf) - j - 1]; + out_key[j] = shabuf[j]; } blake2b_init (&bs, BLAKE2B_OUTBYTES); cur_key = out_key; diff --git a/test/rspamd_shingles_test.c b/test/rspamd_shingles_test.c index 44bc1e789..e6cd0abb3 100644 --- a/test/rspamd_shingles_test.c +++ b/test/rspamd_shingles_test.c @@ -107,7 +107,7 @@ test_case (gsize cnt, gsize max_len, gdouble perm_factor) res = rspamd_shingles_compare (sgl, sgl_permuted); - msg_debug ("percentage of common shingles: %.3f, generate time: %Hd usec", + msg_debug ("percentage of common shingles: %.3f, generate time: %hd usec", res, ts_to_usec (&ts2) - ts_to_usec (&ts1)); g_assert_cmpfloat (fabs ((1.0 - res) - sqrt (perm_factor)), <=, 0.20);