Skip to content

Commit

Permalink
RISC-V: Improve handling of mapping symbols with dot suffix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
a4lg committed Oct 19, 2023
1 parent 6f85247 commit c7187ed
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c7187ed

Please sign in to comment.