From fa8d7adf33986302100313a791418423a7d4c758 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Fri, 5 May 2017 09:37:26 -0700 Subject: [PATCH] Avoid accessing null target->reg_cache GDB might request registers even if target was not successfully initialized. --- src/target/riscv/riscv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 42c2f8721..d754cd67d 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -414,6 +414,12 @@ static int riscv_get_gdb_reg_list(struct target *target, if (!*reg_list) { return ERROR_FAIL; } + + if (!target->reg_cache) { + LOG_ERROR("Target not initialized. Return ERROR_FAIL."); + return ERROR_FAIL; + } + for (int i = 0; i < *reg_list_size; i++) { assert(target->reg_cache->reg_list[i].size > 0); (*reg_list)[i] = &target->reg_cache->reg_list[i];