Skip to content

Commit 3bc9421

Browse files
committed
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.
1 parent d08515a commit 3bc9421

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

opcodes/riscv-dis.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -875,12 +875,12 @@ riscv_get_map_state (int n,
875875
char *suffix = strchr (name, '.');
876876
if (suffix)
877877
{
878-
int suffix_index = (int)(suffix - name);
879-
char *name_substr = xmalloc (suffix_index + 1);
880-
strncpy (name_substr, name, suffix_index);
881-
name_substr[suffix_index] = '\0';
882-
riscv_parse_subset (&riscv_rps_dis, name_substr + 2);
883-
free (name_substr);
878+
size_t arch_len = (size_t) (suffix - name) - 2;
879+
char *arch = xmalloc (arch_len + 1);
880+
memcpy (arch, name + 2, arch_len);
881+
arch[arch_len] = '\0';
882+
riscv_parse_subset (&riscv_rps_dis, arch);
883+
free (arch);
884884
}
885885
else
886886
riscv_parse_subset (&riscv_rps_dis, name + 2);

0 commit comments

Comments
 (0)