diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-14 16:40:59 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-14 16:40:59 +0100 |
commit | 193d16686261feacf5ab2ff13642cadbc47287a5 (patch) | |
tree | 6e92ecaab3c9ba2e910420ebea93c89e6c66551e /src/libutil | |
parent | ea53cb781388f3d07ac29170267678003633a17b (diff) | |
download | rspamd-193d16686261feacf5ab2ff13642cadbc47287a5.tar.gz rspamd-193d16686261feacf5ab2ff13642cadbc47287a5.zip |
Fix union usage.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c index 506d5b0e0..221637597 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -1261,11 +1261,13 @@ rspamd_strcase_equal (gconstpointer v, gconstpointer v2) static guint rspamd_icase_hash (const gchar *in, gsize len) { - guint leftover = len % 8; + guint leftover = len % 4; guint fp, i; const uint8_t* s = (const uint8_t*) in; union { - guchar c1, c2, c3, c4; + struct { + guchar c1, c2, c3, c4; + } c; guint32 pp; } u; XXH64_state_t st; @@ -1274,23 +1276,23 @@ rspamd_icase_hash (const gchar *in, gsize len) XXH64_reset (&st, 0xdeadbabe); for (i = 0; i != fp; i += 4) { - u.c1 = s[i], u.c2 = s[i + 1], u.c3 = s[i + 2], u.c4 = s[i + 3]; - u.c1 = lc_map[u.c1]; - u.c2 = lc_map[u.c2]; - u.c3 = lc_map[u.c3]; - u.c4 = lc_map[u.c4]; + u.c.c1 = s[i], u.c.c2 = s[i + 1], u.c.c3 = s[i + 2], u.c.c4 = s[i + 3]; + u.c.c1 = lc_map[u.c.c1]; + u.c.c2 = lc_map[u.c.c2]; + u.c.c3 = lc_map[u.c.c3]; + u.c.c4 = lc_map[u.c.c4]; XXH64_update (&st, &u.pp, sizeof (u)); } u.pp = 0; switch (leftover) { case 3: - u.c3 = lc_map[(guchar)s[i++]]; + u.c.c3 = lc_map[(guchar)s[i++]]; case 2: - u.c2 = lc_map[(guchar)s[i++]]; + u.c.c2 = lc_map[(guchar)s[i++]]; case 1: - u.c1 = lc_map[(guchar)s[i]]; - XXH64_update (&st, &u.pp, sizeof (u)); + u.c.c1 = lc_map[(guchar)s[i]]; + XXH64_update (&st, &u.pp, leftover); break; } |