From: James Cowgill Date: Thu, 4 May 2017 13:29:48 +0000 (+0100) Subject: memory: switch loop condition around in blas_memory_free X-Git-Tag: upstream/0.2.20^2~26^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=5fecfe0f42ae389dc962981334aa1f2d28272e53;p=platform%2Fupstream%2Fopenblas.git memory: switch loop condition around in blas_memory_free 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. --- diff --git a/driver/others/memory.c b/driver/others/memory.c index 0ac44f6..6c62c68 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -1164,8 +1164,8 @@ void blas_memory_free(void *free_area){ 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;