From 109646c09d9a4d9832c0d93eab363f5f276f9df5 Mon Sep 17 00:00:00 2001 From: Parshintsev Anatoly Date: Wed, 27 Nov 2024 21:36:25 +0300 Subject: [PATCH] fix incorrect parsing of names for custom csr registers this commit fixes a regression introduced in ba8c1eef5a32193d9b5dc80d681a4f18d1d94f11. The regression was caused by removal of these lines: ``` - /* Register prefix: "csr_" or "custom_" */ - strcpy(name, reg_type); - name[strlen(reg_type)] = '_'; ``` causing all CSR names with custom names to be parsed as empty strings. --- src/target/riscv/riscv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index c0fb845e6..f879d5e94 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -4164,12 +4164,16 @@ static int parse_reg_ranges_impl(struct list_head *ranges, char *args, } const char * const reg_name_in = equals + 1; - *name_buffer = calloc(1, strlen(reg_name_in) + strlen(reg_type) + 2); + const size_t reg_type_len = strlen(reg_type); + /* format is: _\0 */ + *name_buffer = calloc(1, strlen(reg_name_in) + reg_type_len + 2); name = *name_buffer; if (!name) { LOG_ERROR("Out of memory"); return ERROR_FAIL; } + strcpy(name, reg_type); + name[reg_type_len] = '_'; unsigned int scanned_chars; char *scan_dst = name + strlen(reg_type) + 1;