Core/DSP/DSPTables: Make use of fmt::format in pdname()

Resolves a deprecation warning on macOS. Also, we can convert
the function to just return a std::string instead of using a
static internal buffer, which is gross and thread-unsafe.
This commit is contained in:
Lioncache 2023-12-18 10:20:26 -05:00
parent 9abcc1c08b
commit 62740d97a8
2 changed files with 5 additions and 6 deletions

View File

@ -10,6 +10,8 @@
#include <cstddef> #include <cstddef>
#include <cstdio> #include <cstdio>
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
@ -492,18 +494,15 @@ const std::array<pdlabel_t, 36> regnames =
}}; }};
// clang-format on // clang-format on
const char* pdname(u16 val) std::string pdname(u16 val)
{ {
static char tmpstr[12]; // nasty
for (const pdlabel_t& pdlabel : pdlabels) for (const pdlabel_t& pdlabel : pdlabels)
{ {
if (pdlabel.addr == val) if (pdlabel.addr == val)
return pdlabel.name; return pdlabel.name;
} }
sprintf(tmpstr, "0x%04x", val); return fmt::format("0x{:04x}", val);
return tmpstr;
} }
const char* pdregname(int val) const char* pdregname(int val)

View File

@ -93,7 +93,7 @@ struct pdlabel_t
extern const std::array<pdlabel_t, 36> regnames; extern const std::array<pdlabel_t, 36> regnames;
extern const std::array<pdlabel_t, 96> pdlabels; extern const std::array<pdlabel_t, 96> pdlabels;
const char* pdname(u16 val); std::string pdname(u16 val);
const char* pdregname(int val); const char* pdregname(int val);
const char* pdregnamelong(int val); const char* pdregnamelong(int val);