From 86fb922f54c8a4def1a6aefc1dca124f436e34cc Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Fri, 24 Nov 2023 10:30:18 +0100 Subject: [PATCH] Cleanup: BLI: add assertion for uninitialized boolean in IndexMask.from_predicate Not properly initialized booleans cause problems due to the branchless increment. Pull Request: https://projects.blender.org/blender/blender/pulls/115338 --- source/blender/blenlib/BLI_index_mask.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/blenlib/BLI_index_mask.hh b/source/blender/blenlib/BLI_index_mask.hh index 5c975352f5a..2940694f143 100644 --- a/source/blender/blenlib/BLI_index_mask.hh +++ b/source/blender/blenlib/BLI_index_mask.hh @@ -851,6 +851,9 @@ inline IndexMask IndexMask::from_predicate(const IndexMask &universe, const int64_t global_index = int64_t(local_index) + offset; const bool condition = predicate(global_index); *r_current = local_index; + /* This expects the boolean to be either 0 or 1 which is generally the case but may not + * be if the values are uninitialized. */ + BLI_assert(ELEM(int8_t(condition), 0, 1)); /* Branchless conditional increment. */ r_current += condition; }