From c7187ed07616ae71e7d763b9ed0c364dafcbb999 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sat, 14 Oct 2023 07:49:34 +0000 Subject: [PATCH] RISC-V: Improve handling of mapping symbols with dot suffix This commit makes minor improvements to mapping symbols (executable) handling with a dot suffix. 1. Use size_t instead of int 2. Allocate minimum size for the architectural string buffer. 3. memcpy instead of strncpy because we know the exact size to copy. 4. Minor variable naming changes. opcodes/ChangeLog: * riscv-dis.c (riscv_get_map_state): Minor improvements to handling of executable mapping symbols with dot suffix. --- opcodes/riscv-dis.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 216916e9426..18547d81c20 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -875,12 +875,12 @@ riscv_get_map_state (int n, char *suffix = strchr (name, '.'); if (suffix) { - int suffix_index = (int)(suffix - name); - char *name_substr = xmalloc (suffix_index + 1); - strncpy (name_substr, name, suffix_index); - name_substr[suffix_index] = '\0'; - riscv_parse_subset (&riscv_rps_dis, name_substr + 2); - free (name_substr); + size_t arch_len = (size_t) (suffix - name) - 2; + char *arch = xmalloc (arch_len + 1); + memcpy (arch, name + 2, arch_len); + arch[arch_len] = '\0'; + riscv_parse_subset (&riscv_rps_dis, arch); + free (arch); } else riscv_parse_subset (&riscv_rps_dis, name + 2);