diff --git a/pcsx2/x86/iR3000A.cpp b/pcsx2/x86/iR3000A.cpp index 618c2e4a4c..01344477b3 100644 --- a/pcsx2/x86/iR3000A.cpp +++ b/pcsx2/x86/iR3000A.cpp @@ -101,56 +101,59 @@ static void iopRecError(int err); static ZydisFormatterFunc s_old_print_address; static ZydisFormatterFunc s_old_print_disp; -static int Address2Symbol(u64 address, char* buf) +static bool Address2Symbol(u64 address, SmallString &buf) { - u32 len = 0; #define A(x) ((u64)(x)) if (address >= A(iopMem->Main) && address < A(iopMem->P)) { - len = sprintf(buf, "iopMem+0x%08X", static_cast(address - A(iopMem->Main))); + buf.append_format("iopMem+0x{:08X}", static_cast(address - A(iopMem->Main))); } else if (address >= A(&psxRegs.GPR) && address < A(&psxRegs.CP0)) { - len = sprintf(buf, "psxRegs.GPR.%s", R3000A::disRNameGPR[static_cast(address - A(&psxRegs)) / 4u]); + buf.append_format("psxRegs.GPR.{}", R3000A::disRNameGPR[static_cast(address - A(&psxRegs)) / 4u]); } else if (address == A(&psxRegs.pc)) { - len = sprintf(buf, "psxRegs.pc"); + buf.append("psxRegs.pc"); } else if (address == A(&psxRegs.cycle)) { - len = sprintf(buf, "psxRegs.cycle"); + buf.append("psxRegs.cycle"); } else if (address == A(&psxRegs.iopNextEventCycle)) { - len = sprintf(buf, "psxRegs.iopNextEventCycle"); + buf.append("psxRegs.iopNextEventCycle"); + } + else + { + return false; } #undef A - return len; + return true; } static ZyanStatus ZydisFormatterPrintDisplacement(const ZydisFormatter* formatter, ZydisFormatterBuffer* buffer, ZydisFormatterContext* context) { - char buf[128]; - u32 len = 0; u64 address = (u64)R3000A_TEXTPTR + context->operand->mem.disp.value; + bool did_print = false; + SmallString buf; // hardcoded RTEXTPTR if (context->operand->mem.base == ZYDIS_REGISTER_RBX) { - len = Address2Symbol(address, buf); + did_print = Address2Symbol(address, buf); } - if (len > 0) + if (did_print) { ZYAN_CHECK(ZydisFormatterBufferAppend(buffer, ZYDIS_TOKEN_SYMBOL)); ZyanString* string; ZYAN_CHECK(ZydisFormatterBufferGetString(buffer, &string)); - return ZyanStringAppendFormat(string, "-%s+&%s", "R3000A_TEXTPTR", buf); + return ZyanStringAppendFormat(string, "-%s+&%s", "R3000A_TEXTPTR", buf.c_str()); } return s_old_print_disp(formatter, buffer, context); @@ -163,17 +166,17 @@ static ZyanStatus ZydisFormatterPrintAddressAbsolute(const ZydisFormatter* forma ZYAN_CHECK(ZydisCalcAbsoluteAddress(context->instruction, context->operand, context->runtime_address, &address)); - char buf[128]; - u32 len = 0; + SmallString buf; + bool did_print = false; - len = Address2Symbol(address, buf); + did_print = Address2Symbol(address, buf); - if (len > 0) + if (did_print) { ZYAN_CHECK(ZydisFormatterBufferAppend(buffer, ZYDIS_TOKEN_SYMBOL)); ZyanString* string; ZYAN_CHECK(ZydisFormatterBufferGetString(buffer, &string)); - return ZyanStringAppendFormat(string, "&%s", buf); + return ZyanStringAppendFormat(string, "&%s", buf.c_str()); } return s_old_print_address(formatter, buffer, context);