From fddad99f1121f7e4351dcff06d0b9269f3f32e9d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 1 Oct 2017 00:12:25 +0100 Subject: [PATCH 1/2] 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 --- src/libostree/ostree-bloom.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libostree/ostree-bloom.c b/src/libostree/ostree-bloom.c index 6b42d97a78..8defb17673 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))); } } From a2899443a0bf427ca5adce12d395813a5eda90d7 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 1 Oct 2017 00:13:17 +0100 Subject: [PATCH 2/2] lib/bloom: Fix a -Wconversion warning in OstreeBloom Compiling with -Wconversion warns on this line, as the conversion from guint64 to guint8 is implicit (but safe: there is no bug here, since the implicit cast is applied after the modulus arithmetic). Make the cast explicit to silence -Wconversion. Signed-off-by: Philip Withnall --- src/libostree/ostree-bloom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libostree/ostree-bloom.c b/src/libostree/ostree-bloom.c index 8defb17673..9bd2ad2835 100644 --- a/src/libostree/ostree-bloom.c +++ b/src/libostree/ostree-bloom.c @@ -246,7 +246,7 @@ ostree_bloom_set_bit (OstreeBloom *bloom, { g_assert (bloom->is_mutable); g_assert (idx / 8 < bloom->n_bytes); - bloom->mutable_bytes[idx / 8] |= (1 << (idx % 8)); + bloom->mutable_bytes[idx / 8] |= (guint8) (1 << (idx % 8)); } /**