diff options
author | Andrew Waterman <andrew@sifive.com> | 2022-12-04 21:38:17 -1000 |
---|---|---|
committer | Andrew Waterman <andrew@sifive.com> | 2022-12-05 10:14:11 -1000 |
commit | 9dc874288cb6dcfa1b09411f70cc44f5c532e067 (patch) | |
tree | 9b03bfb2dc7c04574af39afb0ac75a5233c16ee5 /disasm | |
parent | 69bfc0261847861517fab5174ce38df48f8c4b4a (diff) | |
download | riscv-isa-sim-9dc874288cb6dcfa1b09411f70cc44f5c532e067.zip riscv-isa-sim-9dc874288cb6dcfa1b09411f70cc44f5c532e067.tar.gz riscv-isa-sim-9dc874288cb6dcfa1b09411f70cc44f5c532e067.tar.bz2 |
Avoid use of sprintf in disassembler
None of these cases are perf-critical.
It was easy to change one of them to use std::string, but the others
would have required more refactoring. So, simply change them to use
snprintf instead.
Diffstat (limited to 'disasm')
-rw-r--r-- | disasm/disasm.cc | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/disasm/disasm.cc b/disasm/disasm.cc index 856a651..f522df9 100644 --- a/disasm/disasm.cc +++ b/disasm/disasm.cc @@ -1289,14 +1289,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], @@ -1314,7 +1312,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], @@ -1675,7 +1673,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, |