Before this commit, the "position < NUM_BUFFERS" loop condition from
blas_memory_free will be completely optimized away by GCC. This is
because the condition can only be false after undefined behavior has
already been invoked (reading past the end of an array). As a
consequence of this bug, GCC also removes the subsequent if statement
and all the code after the error label because all of it is dead.
This commit switches the loop condition around so it works as intended.
position = 0;
LOCK_COMMAND(&alloc_lock);
- while ((memory[position].addr != free_area)
- && (position < NUM_BUFFERS)) position++;
+ while ((position < NUM_BUFFERS) && (memory[position].addr != free_area))
+ position++;
if (memory[position].addr != free_area) goto error;