diff options
author | Philip Withnall <withnall@endlessm.com> | 2017-10-01 00:12:25 +0100 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-10-01 12:24:46 +0000 |
commit | 1673601510da20b132bcc3fd17d6e0cc9bf837dd (patch) | |
tree | 1eb543aaa930c8cb23cfda7a7cb259a72db2f7e1 /src/libostree/ostree-bloom.c | |
parent | 4262a4b016ec1ca252dfb4b2fcc82a27f643ea63 (diff) | |
download | ostree-1673601510da20b132bcc3fd17d6e0cc9bf837dd.tar.gz |
lib/bloom: Fix bloom hashing on 32-bit architectures
There was an implicit cast from guint64 to gsize (which is 32-bit on
armhf, for example) before the modulus arithmetic which safely narrows
the index.
Fix that by using a guint64 intermediate variable and making the cast
explicit.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #1231
Approved by: cgwalters
Diffstat (limited to 'src/libostree/ostree-bloom.c')
-rw-r--r-- | src/libostree/ostree-bloom.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libostree/ostree-bloom.c b/src/libostree/ostree-bloom.c index 6b42d97a..8defb176 100644 --- a/src/libostree/ostree-bloom.c +++ b/src/libostree/ostree-bloom.c @@ -273,11 +273,11 @@ ostree_bloom_maybe_contains (OstreeBloom *bloom, for (i = 0; i < bloom->k; i++) { - gsize idx; + guint64 idx; idx = bloom->hash_func (element, i); - if (!ostree_bloom_get_bit (bloom, idx % (bloom->n_bytes * 8))) + if (!ostree_bloom_get_bit (bloom, (gsize) (idx % (bloom->n_bytes * 8)))) return FALSE; /* definitely not in the set */ } @@ -337,8 +337,8 @@ ostree_bloom_add_element (OstreeBloom *bloom, for (i = 0; i < bloom->k; i++) { - gsize idx = bloom->hash_func (element, i); - ostree_bloom_set_bit (bloom, idx % (bloom->n_bytes * 8)); + guint64 idx = bloom->hash_func (element, i); + ostree_bloom_set_bit (bloom, (gsize) (idx % (bloom->n_bytes * 8))); } } |