From dc25e4c552ee400c8ed90e64c93a9b6c1229847b Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Sat, 30 Sep 2023 21:54:21 +0200 Subject: [PATCH] cachegrind: exit with error if line size or associativity is zero Detected with Coverity --- cachegrind/cg_arch.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cachegrind/cg_arch.c b/cachegrind/cg_arch.c index 9b6071d2c3..dac22feb2a 100644 --- a/cachegrind/cg_arch.c +++ b/cachegrind/cg_arch.c @@ -41,6 +41,16 @@ static void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* LLc, // string otherwise. static const HChar* check_cache(cache_t* cache) { + if (cache->line_size == 0) + { + return "Cache line size is zero.\n"; + } + + if (cache->assoc == 0) + { + return "Cache associativity is zero.\n"; + } + // Simulator requires set count to be a power of two. if ((cache->size % (cache->line_size * cache->assoc) != 0) || (-1 == VG_(log2)(cache->size/cache->line_size/cache->assoc))) -- 2.47.2