aboutsummaryrefslogtreecommitdiff
path: root/disasm
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2022-12-05 16:10:56 -1000
committerGitHub <noreply@github.com>2022-12-05 16:10:56 -1000
commitb09a4dc2ae8185fc53991f33d09c407526e83457 (patch)
tree3482acba2e0f0499d97ecc1ec091a6e9267ae8f4 /disasm
parent27caa02e7df9b4feb74003592535bd3c71037c75 (diff)
parent9dc874288cb6dcfa1b09411f70cc44f5c532e067 (diff)
downloadriscv-isa-sim-b09a4dc2ae8185fc53991f33d09c407526e83457.zip
riscv-isa-sim-b09a4dc2ae8185fc53991f33d09c407526e83457.tar.gz
riscv-isa-sim-b09a4dc2ae8185fc53991f33d09c407526e83457.tar.bz2
Merge pull request #1161 from riscv-software-src/snprintf
Avoid use of sprintf
Diffstat (limited to 'disasm')
-rw-r--r--disasm/disasm.cc10
1 files changed, 4 insertions, 6 deletions
diff --git a/disasm/disasm.cc b/disasm/disasm.cc
index 0ec67bd..bc82024 100644
--- a/disasm/disasm.cc
+++ b/disasm/disasm.cc
@@ -1392,14 +1392,12 @@ void disassembler_t::add_instructions(const isa_parser_t* isa)
0x10000000, 0x10005000, 0x10006000, 0x10007000};
for (unsigned nf = 0; nf <= 7; ++nf) {
- char seg_str[8] = "";
- if (nf)
- sprintf(seg_str, "seg%u", nf + 1);
+ const auto seg_str = nf ? "seg" + std::to_string(nf + 1) : "";
for (auto item : template_insn) {
const reg_t match_nf = nf << 29;
char buf[128];
- sprintf(buf, item.fmt, seg_str, 8 << elt);
+ snprintf(buf, sizeof(buf), item.fmt, seg_str.c_str(), 8 << elt);
add_insn(new disasm_insn_t(
buf,
((item.match | match_nf) & ~mask_vldst) | elt_map[elt],
@@ -1417,7 +1415,7 @@ void disassembler_t::add_instructions(const isa_parser_t* isa)
for (auto item : template_insn2) {
const reg_t match_nf = nf << 29;
char buf[128];
- sprintf(buf, item.fmt, nf + 1, 8 << elt);
+ snprintf(buf, sizeof(buf), item.fmt, nf + 1, 8 << elt);
add_insn(new disasm_insn_t(
buf,
item.match | match_nf | elt_map[elt],
@@ -1778,7 +1776,7 @@ void disassembler_t::add_instructions(const isa_parser_t* isa)
for (size_t idx = 0; idx < sizeof(amo_map) / sizeof(amo_map[0]); ++idx) {
for (auto item : template_insn) {
char buf[128];
- sprintf(buf, item.fmt, amo_map[idx].first, 8 << elt);
+ snprintf(buf, sizeof(buf), item.fmt, amo_map[idx].first, 8 << elt);
add_insn(new disasm_insn_t(buf,
item.match | amo_map[idx].second | elt_map[elt],
item.mask,