DebugTools: Replace sprintf() with snprintf()

This commit is contained in:
Stenzek 2023-10-02 02:06:07 +10:00 committed by Connor McLaughlin
parent 61ce0d1117
commit bf2cdc3c9b
11 changed files with 107 additions and 100 deletions

View File

@ -31,6 +31,11 @@
#include "common/StringUtil.h" #include "common/StringUtil.h"
#ifdef __clang__
// TODO: The sprintf() usage here needs to be rewritten...
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
R5900DebugInterface r5900Debug; R5900DebugInterface r5900Debug;
R3000DebugInterface r3000Debug; R3000DebugInterface r3000Debug;
@ -67,7 +72,7 @@ public:
for (int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
{ {
char reg[8]; char reg[8];
sprintf(reg, "r%d", i); std::snprintf(reg, std::size(reg), "r%d", i);
if (strcasecmp(str, reg) == 0 || strcasecmp(str, cpu->getRegisterName(0, i)) == 0) if (strcasecmp(str, reg) == 0 || strcasecmp(str, cpu->getRegisterName(0, i)) == 0)
{ {

View File

@ -45,7 +45,7 @@ typedef char* (*TdisR3000AF)(u32 code, u32 pc);
#define MakeDisFg(fn, b) char* fn(u32 code, u32 pc) { b; return ostr; } #define MakeDisFg(fn, b) char* fn(u32 code, u32 pc) { b; return ostr; }
#define MakeDisF(fn, b) \ #define MakeDisF(fn, b) \
static char* fn(u32 code, u32 pc) { \ static char* fn(u32 code, u32 pc) { \
sprintf (ostr, "%8.8x %8.8x:", pc, code); \ std::snprintf(ostr, sizeof(ostr), "%8.8x %8.8x:", pc, code); \
b; /*ostr[(strlen(ostr) - 1)] = 0;*/ return ostr; \ b; /*ostr[(strlen(ostr) - 1)] = 0;*/ return ostr; \
} }
@ -69,17 +69,17 @@ typedef char* (*TdisR3000AF)(u32 code, u32 pc);
#define _Branch_ (pc + 4 + ((short)_Im_ * 4)) #define _Branch_ (pc + 4 + ((short)_Im_ * 4))
#define _OfB_ _Im_, _nRs_ #define _OfB_ _Im_, _nRs_
#define dName(i) sprintf(ostr + strlen(ostr), " %-7s,", i) #define dName(i) std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %-7s,", i)
#define dGPR(i) sprintf(ostr + strlen(ostr), " %8.8x (%s),", psxRegs.GPR.r[i], disRNameGPR[i]) #define dGPR(i) std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %8.8x (%s),", psxRegs.GPR.r[i], disRNameGPR[i])
#define dCP0(i) sprintf(ostr + strlen(ostr), " %8.8x (%s),", psxRegs.CP0.r[i], disRNameCP0[i]) #define dCP0(i) std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %8.8x (%s),", psxRegs.CP0.r[i], disRNameCP0[i])
#define dHI() sprintf(ostr + strlen(ostr), " %8.8x (%s),", psxRegs.GPR.n.hi, "hi") #define dHI() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %8.8x (%s),", psxRegs.GPR.n.hi, "hi")
#define dLO() sprintf(ostr + strlen(ostr), " %8.8x (%s),", psxRegs.GPR.n.lo, "lo") #define dLO() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %8.8x (%s),", psxRegs.GPR.n.lo, "lo")
#define dImm() sprintf(ostr + strlen(ostr), " %4.4x (%d),", _Im_, _Im_) #define dImm() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %4.4x (%d),", _Im_, _Im_)
#define dTarget() sprintf(ostr + strlen(ostr), " %8.8x,", _InstrucTarget_) #define dTarget() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %8.8x,", _InstrucTarget_)
#define dSa() sprintf(ostr + strlen(ostr), " %2.2x (%d),", _Sa_, _Sa_) #define dSa() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %2.2x (%d),", _Sa_, _Sa_)
#define dOfB() sprintf(ostr + strlen(ostr), " %4.4x (%8.8x (%s)),", _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_]) #define dOfB() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %4.4x (%8.8x (%s)),", _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_])
#define dOffset() sprintf(ostr + strlen(ostr), " %8.8x,", _Branch_) #define dOffset() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %8.8x,", _Branch_)
#define dCode() sprintf(ostr + strlen(ostr), " %8.8x,", (code >> 6) & 0xffffff) #define dCode() std::snprintf(ostr + std::strlen(ostr), std::size(ostr) - std::strlen(ostr), " %8.8x,", (code >> 6) & 0xffffff)
/********************************************************* /*********************************************************
* Arithmetic with immediate operand * * Arithmetic with immediate operand *

View File

@ -697,7 +697,7 @@ void P_COP2_Unknown( std::string& output )
void label_decode( std::string& output, u32 addr ) void label_decode( std::string& output, u32 addr )
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "->$0x%08X", addr); std::snprintf(buffer, std::size(buffer), "->$0x%08X", addr);
output += std::string(buffer); output += std::string(buffer);
} }
@ -751,9 +751,9 @@ const char* signedImmediate(s32 imm, int len = 0)
static char buffer[32]; static char buffer[32];
if (imm >= 0) if (imm >= 0)
sprintf(buffer,"0x%*X",len,imm); std::snprintf(buffer,std::size(buffer),"0x%*X",len,imm);
else else
sprintf(buffer,"-0x%*X",len,-imm); std::snprintf(buffer,std::size(buffer),"-0x%*X",len,-imm);
return buffer; return buffer;
} }
@ -762,12 +762,12 @@ const char* disDestSource(int dest, int source)
{ {
static char buffer[64]; static char buffer[64];
#ifdef PRINT_REG_CONTENT #ifdef PRINT_REG_CONTENT
sprintf(buffer,"%s,%s(0x%8.8x)",GPR_REG[dest],GPR_REG[source], cpuRegs.GPR.r[source].UL[0]); std::snprintf(buffer,std::size(buffer),"%s,%s(0x%8.8x)",GPR_REG[dest],GPR_REG[source], cpuRegs.GPR.r[source].UL[0]);
#else #else
if (disSimplify && dest == source) if (disSimplify && dest == source)
sprintf(buffer,"%s",GPR_REG[dest]); std::snprintf(buffer,std::size(buffer),"%s",GPR_REG[dest]);
else else
sprintf(buffer,"%s,%s",GPR_REG[dest],GPR_REG[source]); std::snprintf(buffer,std::size(buffer),"%s,%s",GPR_REG[dest],GPR_REG[source]);
#endif #endif

View File

@ -19,7 +19,8 @@
#include "Debug.h" #include "Debug.h"
static char ostr[1024]; static char ostr[1024];
#define ostrA (ostr + strlen(ostr)) #define ostrA (ostr + std::strlen(ostr))
#define ostrAL (std::size(ostr) - std::strlen(ostr))
// Type deffinition of our functions // Type deffinition of our functions
#define DisFInterface (u32 code, u32 pc) #define DisFInterface (u32 code, u32 pc)
@ -31,7 +32,7 @@ typedef char* (*TdisR5900F)DisFInterface;
// These macros are used to assemble the disassembler functions // These macros are used to assemble the disassembler functions
#define MakeDisF(fn, b) \ #define MakeDisF(fn, b) \
char* fn DisFInterface { \ char* fn DisFInterface { \
sprintf (ostr, "%8.8x %8.8x:", pc, code); \ std::snprintf (ostr, std::size(ostr), "%8.8x %8.8x:", pc, code); \
b; \ b; \
return ostr; \ return ostr; \
} }
@ -44,22 +45,22 @@ typedef char* (*TdisR5900F)DisFInterface;
#define _Is_ (_Fs_ & 15) #define _Is_ (_Fs_ & 15)
#define _Id_ (_Fd_ & 15) #define _Id_ (_Fd_ & 15)
#define dName(i) sprintf(ostrA, " %-7s,", i) #define dName(i) std::snprintf(ostrA, ostrAL, " %-7s,", i)
#define dNameU(i) { char op[256]; sprintf(op, "%s.%s%s%s%s", i, _X ? "x" : "", _Y ? "y" : "", _Z ? "z" : "", _W ? "w" : ""); sprintf(ostrA, " %-7s,", op); } #define dNameU(i) { char op[256]; std::snprintf(op, std::size(op), "%s.%s%s%s%s", i, _X ? "x" : "", _Y ? "y" : "", _Z ? "z" : "", _W ? "w" : ""); std::snprintf(ostrA, ostrAL, " %-7s,", op); }
#define dCP2128f(i) sprintf(ostrA, " w=%f z=%f y=%f x=%f (%s),", VU0.VF[i].f.w, VU0.VF[i].f.z, VU0.VF[i].f.y, VU0.VF[i].f.x, R5900::COP2_REG_FP[i]) #define dCP2128f(i) std::snprintf(ostrA, ostrAL, " w=%f z=%f y=%f x=%f (%s),", VU0.VF[i].f.w, VU0.VF[i].f.z, VU0.VF[i].f.y, VU0.VF[i].f.x, R5900::COP2_REG_FP[i])
#define dCP232x(i) sprintf(ostrA, " x=%f (%s),", VU0.VF[i].f.x, R5900::COP2_REG_FP[i]) #define dCP232x(i) std::snprintf(ostrA, ostrAL, " x=%f (%s),", VU0.VF[i].f.x, R5900::COP2_REG_FP[i])
#define dCP232y(i) sprintf(ostrA, " y=%f (%s),", VU0.VF[i].f.y, R5900::COP2_REG_FP[i]) #define dCP232y(i) std::snprintf(ostrA, ostrAL, " y=%f (%s),", VU0.VF[i].f.y, R5900::COP2_REG_FP[i])
#define dCP232z(i) sprintf(ostrA, " z=%f (%s),", VU0.VF[i].f.z, R5900::COP2_REG_FP[i]) #define dCP232z(i) std::snprintf(ostrA, ostrAL, " z=%f (%s),", VU0.VF[i].f.z, R5900::COP2_REG_FP[i])
#define dCP232w(i) sprintf(ostrA, " w=%f (%s),", VU0.VF[i].f.w, R5900::COP2_REG_FP[i]) #define dCP232w(i) std::snprintf(ostrA, ostrAL, " w=%f (%s),", VU0.VF[i].f.w, R5900::COP2_REG_FP[i])
#define dCP2ACCf() sprintf(ostrA, " w=%f z=%f y=%f x=%f (ACC),", VU0.ACC.f.w, VU0.ACC.f.z, VU0.ACC.f.y, VU0.ACC.f.x) #define dCP2ACCf() std::snprintf(ostrA, ostrAL, " w=%f z=%f y=%f x=%f (ACC),", VU0.ACC.f.w, VU0.ACC.f.z, VU0.ACC.f.y, VU0.ACC.f.x)
#define dCP232i(i) sprintf(ostrA, " %8.8x (%s),", VU0.VI[i].UL, R5900::COP2_REG_CTL[i]) #define dCP232i(i) std::snprintf(ostrA, ostrAL, " %8.8x (%s),", VU0.VI[i].UL, R5900::COP2_REG_CTL[i])
#define dCP232iF(i) sprintf(ostrA, " %f (%s),", VU0.VI[i].F, R5900::COP2_REG_CTL[i]) #define dCP232iF(i) std::snprintf(ostrA, ostrAL, " %f (%s),", VU0.VI[i].F, R5900::COP2_REG_CTL[i])
#define dCP232f(i, j) sprintf(ostrA, " Q %s=%f (%s),", R5900::COP2_VFnames[j], VU0.VF[i].F[j], R5900::COP2_REG_FP[i]) #define dCP232f(i, j) std::snprintf(ostrA, ostrAL, " Q %s=%f (%s),", R5900::COP2_VFnames[j], VU0.VF[i].F[j], R5900::COP2_REG_FP[i])
#define dImm5() sprintf(ostrA, " %d,", (code >> 6) & 0x1f) #define dImm5() std::snprintf(ostrA, ostrAL, " %d,", (code >> 6) & 0x1f)
#define dImm11() sprintf(ostrA, " %d,", code & 0x7ff) #define dImm11() std::snprintf(ostrA, ostrAL, " %d,", code & 0x7ff)
#define dImm15() sprintf(ostrA, " %d,", ( ( code >> 10 ) & 0x7800 ) | ( code & 0x7ff )) #define dImm15() std::snprintf(ostrA, ostrAL, " %d,", ( ( code >> 10 ) & 0x7800 ) | ( code & 0x7ff ))
#define _X ((code>>24) & 0x1) #define _X ((code>>24) & 0x1)
#define _Y ((code>>23) & 0x1) #define _Y ((code>>23) & 0x1)

View File

@ -20,7 +20,8 @@
#include "VUmicro.h" #include "VUmicro.h"
static char ostr[1024]; static char ostr[1024];
#define ostrA (ostr + strlen(ostr)) #define ostrA (ostr + std::strlen(ostr))
#define ostrAL (std::size(ostr) - std::strlen(ostr))
// Type deffinition of our functions // Type deffinition of our functions
#define DisFInterface (u32 code, u32 pc) #define DisFInterface (u32 code, u32 pc)
@ -32,7 +33,7 @@ typedef char* (*TdisR5900F)DisFInterface;
// These macros are used to assemble the disassembler functions // These macros are used to assemble the disassembler functions
#define MakeDisF(fn, b) \ #define MakeDisF(fn, b) \
char* fn DisFInterface { \ char* fn DisFInterface { \
if( !!CpuVU1->IsInterpreter ) sprintf (ostr, "%8.8x %8.8x:", pc, code); \ if( !!CpuVU1->IsInterpreter ) std::snprintf(ostr, std::size(ostr), "%8.8x %8.8x:", pc, code); \
else ostr[0] = 0; \ else ostr[0] = 0; \
b; \ b; \
return ostr; \ return ostr; \
@ -46,61 +47,61 @@ typedef char* (*TdisR5900F)DisFInterface;
#define _Is_ (_Fs_ & 15) #define _Is_ (_Fs_ & 15)
#define _Id_ (_Fd_ & 15) #define _Id_ (_Fd_ & 15)
#define dName(i) sprintf(ostrA, " %-12s", i); \ #define dName(i) std::snprintf(ostrA, ostrAL, " %-12s", i); \
#define dNameU(i) { \ #define dNameU(i) { \
char op[256]; sprintf(op, "%s.%s%s%s%s", i, _X ? "x" : "", _Y ? "y" : "", _Z ? "z" : "", _W ? "w" : ""); \ char op[256]; std::snprintf(op, std::size(op), "%s.%s%s%s%s", i, _X ? "x" : "", _Y ? "y" : "", _Z ? "z" : "", _W ? "w" : ""); \
sprintf(ostrA, " %-12s", op); \ std::snprintf(ostrA, ostrAL, " %-12s", op); \
} }
#define dCP2128f(i) { \ #define dCP2128f(i) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s,", R5900::COP2_REG_FP[i]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s,", R5900::COP2_REG_FP[i]); \
else sprintf(ostrA, " w=%f (%8.8x) z=%f (%8.8x) y=%f (%8.8x) x=%f (%8.8x) (%s),", VU1.VF[i].f.w, VU1.VF[i].UL[3], VU1.VF[i].f.z, VU1.VF[i].UL[2], VU1.VF[i].f.y, VU1.VF[i].UL[1], VU1.VF[i].f.x, VU1.VF[i].UL[0], R5900::COP2_REG_FP[i]); \ else std::snprintf(ostrA, ostrAL, " w=%f (%8.8x) z=%f (%8.8x) y=%f (%8.8x) x=%f (%8.8x) (%s),", VU1.VF[i].f.w, VU1.VF[i].UL[3], VU1.VF[i].f.z, VU1.VF[i].UL[2], VU1.VF[i].f.y, VU1.VF[i].UL[1], VU1.VF[i].f.x, VU1.VF[i].UL[0], R5900::COP2_REG_FP[i]); \
} \ } \
#define dCP232x(i) { \ #define dCP232x(i) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s,", R5900::COP2_REG_FP[i]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s,", R5900::COP2_REG_FP[i]); \
else sprintf(ostrA, " x=%f (%s),", VU1.VF[i].f.x, R5900::COP2_REG_FP[i]); \ else std::snprintf(ostrA, ostrAL, " x=%f (%s),", VU1.VF[i].f.x, R5900::COP2_REG_FP[i]); \
} \ } \
#define dCP232y(i) { \ #define dCP232y(i) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s,", R5900::COP2_REG_FP[i]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s,", R5900::COP2_REG_FP[i]); \
else sprintf(ostrA, " y=%f (%s),", VU1.VF[i].f.y, R5900::COP2_REG_FP[i]); \ else std::snprintf(ostrA, ostrAL, " y=%f (%s),", VU1.VF[i].f.y, R5900::COP2_REG_FP[i]); \
} \ } \
#define dCP232z(i) { \ #define dCP232z(i) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s,", R5900::COP2_REG_FP[i]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s,", R5900::COP2_REG_FP[i]); \
else sprintf(ostrA, " z=%f (%s),", VU1.VF[i].f.z, R5900::COP2_REG_FP[i]); \ else std::snprintf(ostrA, ostrAL, " z=%f (%s),", VU1.VF[i].f.z, R5900::COP2_REG_FP[i]); \
} }
#define dCP232w(i) { \ #define dCP232w(i) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s,", R5900::COP2_REG_FP[i]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s,", R5900::COP2_REG_FP[i]); \
else sprintf(ostrA, " w=%f (%s),", VU1.VF[i].f.w, R5900::COP2_REG_FP[i]); \ else std::snprintf(ostrA, ostrAL, " w=%f (%s),", VU1.VF[i].f.w, R5900::COP2_REG_FP[i]); \
} }
#define dCP2ACCf() { \ #define dCP2ACCf() { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " ACC,"); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " ACC,"); \
else sprintf(ostrA, " w=%f z=%f y=%f x=%f (ACC),", VU1.ACC.f.w, VU1.ACC.f.z, VU1.ACC.f.y, VU1.ACC.f.x); \ else std::snprintf(ostrA, ostrAL, " w=%f z=%f y=%f x=%f (ACC),", VU1.ACC.f.w, VU1.ACC.f.z, VU1.ACC.f.y, VU1.ACC.f.x); \
} \ } \
#define dCP232i(i) { \ #define dCP232i(i) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s,", R5900::COP2_REG_CTL[i]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s,", R5900::COP2_REG_CTL[i]); \
else sprintf(ostrA, " %8.8x (%s),", VU1.VI[i].UL, R5900::COP2_REG_CTL[i]); \ else std::snprintf(ostrA, ostrAL, " %8.8x (%s),", VU1.VI[i].UL, R5900::COP2_REG_CTL[i]); \
} }
#define dCP232iF(i) { \ #define dCP232iF(i) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s,", R5900::COP2_REG_CTL[i]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s,", R5900::COP2_REG_CTL[i]); \
else sprintf(ostrA, " %f (%s),", VU1.VI[i].F, R5900::COP2_REG_CTL[i]); \ else std::snprintf(ostrA, ostrAL, " %f (%s),", VU1.VI[i].F, R5900::COP2_REG_CTL[i]); \
} }
#define dCP232f(i, j) { \ #define dCP232f(i, j) { \
if( !CpuVU1->IsInterpreter ) sprintf(ostrA, " %s%s,", R5900::COP2_REG_FP[i], R5900::COP2_VFnames[j]); \ if( !CpuVU1->IsInterpreter ) std::snprintf(ostrA, ostrAL, " %s%s,", R5900::COP2_REG_FP[i], R5900::COP2_VFnames[j]); \
else sprintf(ostrA, " %s=%f (%s),", R5900::COP2_VFnames[j], VU1.VF[i].F[j], R5900::COP2_REG_FP[i]); \ else std::snprintf(ostrA, ostrAL, " %s=%f (%s),", R5900::COP2_VFnames[j], VU1.VF[i].F[j], R5900::COP2_REG_FP[i]); \
} }
#define dImm5() sprintf(ostrA, " %d,", (s16)((code >> 6) & 0x10 ? 0xfff0 | ((code >> 6) & 0xf) : (code >> 6) & 0xf)) #define dImm5() std::snprintf(ostrA, ostrAL, " %d,", (s16)((code >> 6) & 0x10 ? 0xfff0 | ((code >> 6) & 0xf) : (code >> 6) & 0xf))
#define dImm11() sprintf(ostrA, " %d,", (s16)(code & 0x400 ? 0xfc00 | (code & 0x3ff) : code & 0x3ff)) #define dImm11() std::snprintf(ostrA, ostrAL, " %d,", (s16)(code & 0x400 ? 0xfc00 | (code & 0x3ff) : code & 0x3ff))
#define dImm15() sprintf(ostrA, " %d,", ( ( code >> 10 ) & 0x7800 ) | ( code & 0x7ff )) #define dImm15() std::snprintf(ostrA, ostrAL, " %d,", ( ( code >> 10 ) & 0x7800 ) | ( code & 0x7ff ))
#define _X ((code>>24) & 0x1) #define _X ((code>>24) & 0x1)
#define _Y ((code>>23) & 0x1) #define _Y ((code>>23) & 0x1)

View File

@ -50,17 +50,17 @@ MakeDisF(dis##VU##MI_RGET, dNameU("RGET"); dCP232i(REG_R); dCP2128f(_Ft_);)
MakeDisF(dis##VU##MI_RNEXT, dNameU("RNEXT"); dCP232i(REG_R); dCP2128f(_Ft_);) \ MakeDisF(dis##VU##MI_RNEXT, dNameU("RNEXT"); dCP232i(REG_R); dCP2128f(_Ft_);) \
MakeDisF(dis##VU##MI_RXOR, dNameU("RXOR"); dCP232i(REG_R); dCP232f(_Fs_, _Fsf_);) \ MakeDisF(dis##VU##MI_RXOR, dNameU("RXOR"); dCP232i(REG_R); dCP232f(_Fs_, _Fsf_);) \
MakeDisF(dis##VU##MI_WAITQ, dName("WAITQ"); ) \ MakeDisF(dis##VU##MI_WAITQ, dName("WAITQ"); ) \
MakeDisF(dis##VU##MI_FSAND, dName("FSAND"); dCP232i(_It_); dCP232i(REG_STATUS_FLAG); sprintf(ostrA, " %.3x,", code&0xfff); ) \ MakeDisF(dis##VU##MI_FSAND, dName("FSAND"); dCP232i(_It_); dCP232i(REG_STATUS_FLAG); std::snprintf(ostrA, ostrAL, " %.3x,", code&0xfff); ) \
MakeDisF(dis##VU##MI_FSEQ, dName("FSEQ"); dCP232i(_It_); dCP232i(REG_STATUS_FLAG); sprintf(ostrA, " %.3x,", code&0xfff);) \ MakeDisF(dis##VU##MI_FSEQ, dName("FSEQ"); dCP232i(_It_); dCP232i(REG_STATUS_FLAG); std::snprintf(ostrA, ostrAL, " %.3x,", code&0xfff);) \
MakeDisF(dis##VU##MI_FSOR, dName("FSOR"); dCP232i(_It_); dCP232i(REG_STATUS_FLAG); sprintf(ostrA, " %.3x,", code&0xfff);) \ MakeDisF(dis##VU##MI_FSOR, dName("FSOR"); dCP232i(_It_); dCP232i(REG_STATUS_FLAG); std::snprintf(ostrA, ostrAL, " %.3x,", code&0xfff);) \
MakeDisF(dis##VU##MI_FSSET, dName("FSSET"); dCP232i(REG_STATUS_FLAG);) \ MakeDisF(dis##VU##MI_FSSET, dName("FSSET"); dCP232i(REG_STATUS_FLAG);) \
MakeDisF(dis##VU##MI_FMAND, dName("FMAND"); dCP232i(_It_); dCP232i(REG_MAC_FLAG); dCP232i(_Is_);) \ MakeDisF(dis##VU##MI_FMAND, dName("FMAND"); dCP232i(_It_); dCP232i(REG_MAC_FLAG); dCP232i(_Is_);) \
MakeDisF(dis##VU##MI_FMEQ, dName("FMEQ"); dCP232i(_It_); dCP232i(REG_MAC_FLAG); dCP232i(_Is_);) \ MakeDisF(dis##VU##MI_FMEQ, dName("FMEQ"); dCP232i(_It_); dCP232i(REG_MAC_FLAG); dCP232i(_Is_);) \
MakeDisF(dis##VU##MI_FMOR, dName("FMOR"); dCP232i(_It_); dCP232i(REG_MAC_FLAG); dCP232i(_Is_);) \ MakeDisF(dis##VU##MI_FMOR, dName("FMOR"); dCP232i(_It_); dCP232i(REG_MAC_FLAG); dCP232i(_Is_);) \
MakeDisF(dis##VU##MI_FCAND, dName("FCAND"); dCP232i(1); sprintf(ostrA, " %8.8x,", code&0xffffff); ) \ MakeDisF(dis##VU##MI_FCAND, dName("FCAND"); dCP232i(1); std::snprintf(ostrA, ostrAL, " %8.8x,", code&0xffffff); ) \
MakeDisF(dis##VU##MI_FCEQ, dName("FCEQ"); dCP232i(1); dCP232i(REG_CLIP_FLAG);) \ MakeDisF(dis##VU##MI_FCEQ, dName("FCEQ"); dCP232i(1); dCP232i(REG_CLIP_FLAG);) \
MakeDisF(dis##VU##MI_FCOR, dName("FCOR"); dCP232i(1); dCP232i(REG_CLIP_FLAG);) \ MakeDisF(dis##VU##MI_FCOR, dName("FCOR"); dCP232i(1); dCP232i(REG_CLIP_FLAG);) \
MakeDisF(dis##VU##MI_FCSET, dName("FCSET"); dCP232i(REG_CLIP_FLAG); sprintf(ostrA, " %.6x,", code&0xffffff); ) \ MakeDisF(dis##VU##MI_FCSET, dName("FCSET"); dCP232i(REG_CLIP_FLAG); std::snprintf(ostrA, ostrAL, " %.6x,", code&0xffffff); ) \
MakeDisF(dis##VU##MI_FCGET, dName("FCGET"); dCP232i(_It_); dCP232i(REG_CLIP_FLAG);) \ MakeDisF(dis##VU##MI_FCGET, dName("FCGET"); dCP232i(_It_); dCP232i(REG_CLIP_FLAG);) \
MakeDisF(dis##VU##MI_IBEQ, dName("IBEQ"); dImm11(); dCP232i(_It_); dCP232i(_Is_);) \ MakeDisF(dis##VU##MI_IBEQ, dName("IBEQ"); dImm11(); dCP232i(_It_); dCP232i(_Is_);) \
MakeDisF(dis##VU##MI_IBGEZ, dName("IBEZ"); dImm11(); dCP232i(_It_); dCP232i(_Is_);) \ MakeDisF(dis##VU##MI_IBGEZ, dName("IBEZ"); dImm11(); dCP232i(_It_); dCP232i(_Is_);) \

View File

@ -44,7 +44,7 @@ static u32 computeHash(u32 address, u32 size)
} }
void parseDisasm(SymbolMap& map, const char* disasm, char* opcode, char* arguments, bool insertSymbols) static void parseDisasm(SymbolMap& map, const char* disasm, char* opcode, char* arguments, size_t arguments_size, bool insertSymbols)
{ {
if (*disasm == '(') if (*disasm == '(')
{ {
@ -80,9 +80,9 @@ void parseDisasm(SymbolMap& map, const char* disasm, char* opcode, char* argumen
const std::string addressSymbol = map.GetLabelString(branchTarget); const std::string addressSymbol = map.GetLabelString(branchTarget);
if (!addressSymbol.empty() && insertSymbols) if (!addressSymbol.empty() && insertSymbols)
{ {
arguments += sprintf(arguments,"%s",addressSymbol.c_str()); arguments += std::snprintf(arguments, arguments_size, "%s",addressSymbol.c_str());
} else { } else {
arguments += sprintf(arguments,"0x%08X",branchTarget); arguments += std::snprintf(arguments, arguments_size, "0x%08X",branchTarget);
} }
disasm += 3+2+8; disasm += 3+2+8;
@ -700,7 +700,7 @@ bool DisassemblyOpcode::disassemble(u32 address, DisassemblyLineInfo& dest, bool
char opcode[64],arguments[256]; char opcode[64],arguments[256];
std::string dis = cpu->disasm(address,insertSymbols); std::string dis = cpu->disasm(address,insertSymbols);
parseDisasm(cpu->GetSymbolMap(),dis.c_str(),opcode,arguments,insertSymbols); parseDisasm(cpu->GetSymbolMap(),dis.c_str(),opcode,arguments,std::size(arguments),insertSymbols);
dest.type = DISTYPE_OPCODE; dest.type = DISTYPE_OPCODE;
dest.name = opcode; dest.name = opcode;
dest.params = arguments; dest.params = arguments;
@ -780,9 +780,9 @@ bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo& dest, bool
addressSymbol = cpu->GetSymbolMap().GetLabelString(immediate); addressSymbol = cpu->GetSymbolMap().GetLabelString(immediate);
if (!addressSymbol.empty() && insertSymbols) if (!addressSymbol.empty() && insertSymbols)
{ {
sprintf(buffer,"%s,%s",cpu->getRegisterName(0,rt),addressSymbol.c_str()); std::snprintf(buffer,std::size(buffer),"%s,%s",cpu->getRegisterName(0,rt),addressSymbol.c_str());
} else { } else {
sprintf(buffer,"%s,0x%08X",cpu->getRegisterName(0,rt),immediate); std::snprintf(buffer,std::size(buffer),"%s,0x%08X",cpu->getRegisterName(0,rt),immediate);
} }
dest.params = buffer; dest.params = buffer;
@ -796,9 +796,9 @@ bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo& dest, bool
addressSymbol = cpu->GetSymbolMap().GetLabelString(immediate); addressSymbol = cpu->GetSymbolMap().GetLabelString(immediate);
if (!addressSymbol.empty() && insertSymbols) if (!addressSymbol.empty() && insertSymbols)
{ {
sprintf(buffer,"%s,%s",cpu->getRegisterName(0,rt),addressSymbol.c_str()); std::snprintf(buffer,std::size(buffer),"%s,%s",cpu->getRegisterName(0,rt),addressSymbol.c_str());
} else { } else {
sprintf(buffer,"%s,0x%08X",cpu->getRegisterName(0,rt),immediate); std::snprintf(buffer,std::size(buffer),"%s,0x%08X",cpu->getRegisterName(0,rt),immediate);
} }
dest.params = buffer; dest.params = buffer;
@ -923,9 +923,9 @@ void DisassemblyData::createLines()
} else { } else {
char buffer[64]; char buffer[64];
if (pos == end && b == 0) if (pos == end && b == 0)
strcpy(buffer,"0"); StringUtil::Strlcpy(buffer, "0", std::size(buffer));
else else
sprintf(buffer,"0x%02X",b); std::snprintf(buffer, std::size(buffer), "0x%02X", b);
if (currentLine.size()+strlen(buffer) >= maxChars) if (currentLine.size()+strlen(buffer) >= maxChars)
{ {
@ -977,12 +977,12 @@ void DisassemblyData::createLines()
{ {
case DATATYPE_BYTE: case DATATYPE_BYTE:
value = memRead8(pos); value = memRead8(pos);
sprintf(buffer,"0x%02X",value); std::snprintf(buffer,std::size(buffer),"0x%02X",value);
pos++; pos++;
break; break;
case DATATYPE_HALFWORD: case DATATYPE_HALFWORD:
value = memRead16(pos); value = memRead16(pos);
sprintf(buffer,"0x%04X",value); std::snprintf(buffer,std::size(buffer),"0x%04X",value);
pos += 2; pos += 2;
break; break;
case DATATYPE_WORD: case DATATYPE_WORD:
@ -990,9 +990,9 @@ void DisassemblyData::createLines()
value = memRead32(pos); value = memRead32(pos);
const std::string label = cpu->GetSymbolMap().GetLabelString(value); const std::string label = cpu->GetSymbolMap().GetLabelString(value);
if (!label.empty()) if (!label.empty())
sprintf(buffer,"%s",label.c_str()); std::snprintf(buffer,std::size(buffer),"%s",label.c_str());
else else
sprintf(buffer,"0x%08X",value); std::snprintf(buffer,std::size(buffer),"0x%08X",value);
pos += 4; pos += 4;
} }
break; break;

View File

@ -15,9 +15,9 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "ExpressionParser.h" #include "ExpressionParser.h"
#include <ctype.h> #include <cctype>
#include <string.h> #include <cstring>
#include <stdio.h> #include <cstdio>
typedef enum { typedef enum {
EXOP_BRACKETL, EXOP_BRACKETR, EXOP_MEML, EXOP_MEMR, EXOP_MEMSIZE, EXOP_SIGNPLUS, EXOP_SIGNMINUS, EXOP_BRACKETL, EXOP_BRACKETR, EXOP_MEML, EXOP_MEMR, EXOP_MEMSIZE, EXOP_SIGNPLUS, EXOP_SIGNMINUS,
@ -255,7 +255,7 @@ bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, Postf
isFloat = true; isFloat = true;
else if (!parseNumber(subStr,16,subPos,value)) else if (!parseNumber(subStr,16,subPos,value))
{ {
sprintf(expressionError,"Invalid number \"%s\"",subStr); std::snprintf(expressionError, std::size(expressionError),"Invalid number \"%s\"",subStr);
return false; return false;
} }
@ -284,14 +284,14 @@ bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, Postf
continue; continue;
} }
sprintf(expressionError,"Invalid symbol \"%s\"",subStr); std::snprintf(expressionError, std::size(expressionError),"Invalid symbol \"%s\"",subStr);
return false; return false;
} else { } else {
int len; int len;
ExpressionOpcodeType type = getExpressionOpcode(&infix[infixPos],len,lastOpcode); ExpressionOpcodeType type = getExpressionOpcode(&infix[infixPos],len,lastOpcode);
if (type == EXOP_NONE) if (type == EXOP_NONE)
{ {
sprintf(expressionError,"Invalid operator at \"%s\"",&infix[infixPos]); std::snprintf(expressionError, std::size(expressionError),"Invalid operator at \"%s\"",&infix[infixPos]);
return false; return false;
} }
@ -306,7 +306,7 @@ bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, Postf
{ {
if (opcodeStack.empty()) if (opcodeStack.empty())
{ {
sprintf(expressionError,"Closing parenthesis without opening one"); std::snprintf(expressionError, std::size(expressionError),"Closing parenthesis without opening one");
return false; return false;
} }
ExpressionOpcodeType t = opcodeStack[opcodeStack.size()-1]; ExpressionOpcodeType t = opcodeStack[opcodeStack.size()-1];
@ -320,7 +320,7 @@ bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, Postf
{ {
if (opcodeStack.empty()) if (opcodeStack.empty())
{ {
sprintf(expressionError,"Closing bracket without opening one"); std::snprintf(expressionError, std::size(expressionError),"Closing bracket without opening one");
return false; return false;
} }
ExpressionOpcodeType t = opcodeStack[opcodeStack.size()-1]; ExpressionOpcodeType t = opcodeStack[opcodeStack.size()-1];
@ -373,7 +373,7 @@ bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, Postf
if (t == EXOP_BRACKETL) // opening bracket without closing one if (t == EXOP_BRACKETL) // opening bracket without closing one
{ {
sprintf(expressionError,"Parenthesis not closed"); std::snprintf(expressionError, std::size(expressionError),"Parenthesis not closed");
return false; return false;
} }
dest.push_back(ExpressionPair(EXCOMM_OP,t)); dest.push_back(ExpressionPair(EXCOMM_OP,t));
@ -388,13 +388,13 @@ bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, Postf
{ {
case EXCOMM_CONST: case EXCOMM_CONST:
case EXCOMM_CONST_FLOAT: case EXCOMM_CONST_FLOAT:
testPos += sprintf(&test[testPos],"0x%04X ",dest[i].second); testPos += std::snprintf(&test[testPos],std::size(test),"0x%04X ",dest[i].second);
break; break;
case EXCOMM_REF: case EXCOMM_REF:
testPos += sprintf(&test[testPos],"r%d ",dest[i].second); testPos += std::snprintf(&test[testPos],std::size(test),"r%d ",dest[i].second);
break; break;
case EXCOMM_OP: case EXCOMM_OP:
testPos += sprintf(&test[testPos],"%s ",ExpressionOpcodes[dest[i].second].Name); testPos += std::snprintf(&test[testPos],std::size(test),"%s ",ExpressionOpcodes[dest[i].second].Name);
break; break;
}; };
} }
@ -432,7 +432,7 @@ bool parsePostfixExpression(PostfixExpression& exp, IExpressionFunctions* funcs,
opcode = exp[num++].second; opcode = exp[num++].second;
if (valueStack.size() < ExpressionOpcodes[opcode].args) if (valueStack.size() < ExpressionOpcodes[opcode].args)
{ {
sprintf(expressionError,"Not enough arguments"); std::snprintf(expressionError, std::size(expressionError),"Not enough arguments");
return false; return false;
} }
for (int l = 0; l < ExpressionOpcodes[opcode].args; l++) for (int l = 0; l < ExpressionOpcodes[opcode].args; l++)
@ -447,7 +447,7 @@ bool parsePostfixExpression(PostfixExpression& exp, IExpressionFunctions* funcs,
case EXOP_MEMSIZE: // must be followed by EXOP_MEM case EXOP_MEMSIZE: // must be followed by EXOP_MEM
if (exp[num++].second != EXOP_MEM) if (exp[num++].second != EXOP_MEM)
{ {
sprintf(expressionError,"Invalid memsize operator"); std::snprintf(expressionError, std::size(expressionError),"Invalid memsize operator");
return false; return false;
} }
@ -491,7 +491,7 @@ bool parsePostfixExpression(PostfixExpression& exp, IExpressionFunctions* funcs,
case EXOP_DIV: // a/b case EXOP_DIV: // a/b
if (arg[0] == 0) if (arg[0] == 0)
{ {
sprintf(expressionError,"Division by zero"); std::snprintf(expressionError, std::size(expressionError),"Division by zero");
return false; return false;
} }
if (useFloat) if (useFloat)
@ -502,7 +502,7 @@ bool parsePostfixExpression(PostfixExpression& exp, IExpressionFunctions* funcs,
case EXOP_MOD: // a%b case EXOP_MOD: // a%b
if (arg[0] == 0) if (arg[0] == 0)
{ {
sprintf(expressionError,"Modulo by zero"); std::snprintf(expressionError, std::size(expressionError),"Modulo by zero");
return false; return false;
} }
valueStack.push_back(arg[1]%arg[0]); valueStack.push_back(arg[1]%arg[0]);
@ -575,7 +575,7 @@ bool parsePostfixExpression(PostfixExpression& exp, IExpressionFunctions* funcs,
case EXOP_TERTELSE: // exp ? exp : exp, else muss zuerst kommen! case EXOP_TERTELSE: // exp ? exp : exp, else muss zuerst kommen!
if (exp[num++].second != EXOP_TERTIF) if (exp[num++].second != EXOP_TERTIF)
{ {
sprintf(expressionError,"Invalid tertiary operator"); std::snprintf(expressionError, std::size(expressionError),"Invalid tertiary operator");
return false; return false;
} }
valueStack.push_back(arg[2]?arg[1]:arg[0]); valueStack.push_back(arg[2]?arg[1]:arg[0]);

View File

@ -131,7 +131,7 @@ namespace MIPSAnalyst
} }
static const char *DefaultFunctionName(char buffer[256], u32 startAddr) { static const char *DefaultFunctionName(char buffer[256], u32 startAddr) {
sprintf(buffer, "z_un_%08x", startAddr); std::snprintf(buffer, 256, "z_un_%08x", startAddr);
return buffer; return buffer;
} }

View File

@ -191,7 +191,7 @@ std::string SymbolMap::GetDescription(unsigned int address) const {
return labelName; return labelName;
char descriptionTemp[256]; char descriptionTemp[256];
sprintf(descriptionTemp, "(%08x)", address); std::snprintf(descriptionTemp, std::size(descriptionTemp), "(%08x)", address);
return descriptionTemp; return descriptionTemp;
} }

View File

@ -206,7 +206,7 @@ static int __Deci2Call(int call, u32 *addr)
{ {
char reqaddr[128]; char reqaddr[128];
if( addr != NULL ) if( addr != NULL )
sprintf( reqaddr, "%x %x %x %x", addr[3], addr[2], addr[1], addr[0] ); std::snprintf(reqaddr, std::size(reqaddr), "%x %x %x %x", addr[3], addr[2], addr[1], addr[0]);
if (!deci2addr) return 1; if (!deci2addr) return 1;