Skip to content

Commit d003d07

Browse files
authored
Merge pull request #14 from syntacore/aap-sc/ubsan_comparator_bsearch
[cherry-pick] target/riscv: fix potential UB reported by ubsan in ac cache lookup
2 parents f5f712e + fa08a3e commit d003d07

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/target/riscv/riscv-013.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ static void ac_cache_insert(struct ac_cache *cache, uint32_t command)
201201

202202
static bool ac_cache_contains(const struct ac_cache *cache, uint32_t command)
203203
{
204+
if (cache->size == 0)
205+
return false;
204206
return bsearch(&command, cache->commands, cache->size,
205207
sizeof(*cache->commands), ac_cache_elem_comparator);
206208
}

0 commit comments

Comments
 (0)