aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2021-08-12 15:19:50 -0400
committerJack O'Connor <[email protected]>2021-08-24 14:05:42 -0400
commitb8e2dda186c69cece5412f8571bfabf14fd3d7ab (patch)
tree5f45370bf2a8ba9a6d498a742862a2473f96e6fd
parent32758e34a412608e253535c69bde2e382d489caa (diff)
add a redundant loop condition to silence GCC warnings
See: https://github.com/BLAKE3-team/BLAKE3/issues/94 https://github.com/BLAKE3-team/BLAKE3/issues/183 https://github.com/BLAKE3-team/BLAKE3/issues/189
-rw-r--r--c/blake3.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/c/blake3.c b/c/blake3.c
index 9998f75..bccf2e4 100644
--- a/c/blake3.c
+++ b/c/blake3.c
@@ -340,12 +340,18 @@ INLINE void compress_subtree_to_parent_node(
uint8_t cv_array[MAX_SIMD_DEGREE_OR_2 * BLAKE3_OUT_LEN];
size_t num_cvs = blake3_compress_subtree_wide(input, input_len, key,
chunk_counter, flags, cv_array);
+ assert(num_cvs <= MAX_SIMD_DEGREE_OR_2);
// If MAX_SIMD_DEGREE is greater than 2 and there's enough input,
// compress_subtree_wide() returns more than 2 chaining values. Condense
// them into 2 by forming parent nodes repeatedly.
uint8_t out_array[MAX_SIMD_DEGREE_OR_2 * BLAKE3_OUT_LEN / 2];
- while (num_cvs > 2) {
+ // The second half of this loop condition is always true, and we just
+ // asserted it above. But GCC can't tell that it's always true, and if NDEBUG
+ // is set on platforms where MAX_SIMD_DEGREE_OR_2 == 2, GCC emits spurious
+ // warnings here. GCC 8.5 is particular sensitive, so if you're changing this
+ // code, test it against that version.
+ while (num_cvs > 2 && num_cvs <= MAX_SIMD_DEGREE_OR_2) {
num_cvs =
compress_parents_parallel(cv_array, num_cvs, key, flags, out_array);
memcpy(cv_array, out_array, num_cvs * BLAKE3_OUT_LEN);