Replace a few more sprintf with snprintf

This commit is contained in:
Henrik Rydgård 2024-10-15 15:45:19 +02:00
parent 1280fcc581
commit 41eeb491e7
4 changed files with 14 additions and 16 deletions

View File

@ -403,7 +403,7 @@ u32 SymbolMap::GetNextSymbolAddress(u32 address, SymbolType symmask) {
std::string SymbolMap::GetDescription(unsigned int address) {
std::lock_guard<std::recursive_mutex> guard(lock_);
const char* labelName = NULL;
const char *labelName = nullptr;
u32 funcStart = GetFunctionStart(address);
if (funcStart != INVALID_ADDRESS) {
@ -414,11 +414,11 @@ std::string SymbolMap::GetDescription(unsigned int address) {
labelName = GetLabelName(dataStart);
}
if (labelName != NULL)
if (labelName)
return labelName;
char descriptionTemp[256];
sprintf(descriptionTemp, "(%08x)", address);
char descriptionTemp[32];
snprintf(descriptionTemp, sizeof(descriptionTemp), "(%08x)", address);
return descriptionTemp;
}
@ -435,7 +435,7 @@ std::vector<SymbolEntry> SymbolMap::GetAllSymbols(SymbolType symmask) {
entry.address = it->first;
entry.size = GetFunctionSize(entry.address);
const char* name = GetLabelName(entry.address);
if (name != NULL)
if (name)
entry.name = name;
result.push_back(entry);
}
@ -448,7 +448,7 @@ std::vector<SymbolEntry> SymbolMap::GetAllSymbols(SymbolType symmask) {
entry.address = it->first;
entry.size = GetDataSize(entry.address);
const char* name = GetLabelName(entry.address);
if (name != NULL)
if (name)
entry.name = name;
result.push_back(entry);
}

View File

@ -58,7 +58,7 @@ public:
const char *GetTypeName() override { return GetStaticTypeName(); }
static const char *GetStaticTypeName() { return "EventFlag"; }
void GetQuickInfo(char *ptr, int size) override {
sprintf(ptr, "init=%08x cur=%08x numwait=%i",
snprintf(ptr, size, "init=%08x cur=%08x numwait=%i",
nef.initPattern,
nef.currentPattern,
nef.numWaitThreads);

View File

@ -275,10 +275,8 @@ public:
const char *GetName() override { return nm.name; }
const char *GetTypeName() override { return GetStaticTypeName(); }
static const char *GetStaticTypeName() { return "Module"; }
void GetQuickInfo(char *ptr, int size) override
{
// ignore size
sprintf(ptr, "%sname=%s gp=%08x entry=%08x",
void GetQuickInfo(char *ptr, int size) override {
snprintf(ptr, size, "%sname=%s gp=%08x entry=%08x",
isFake ? "faked " : "",
nm.name,
nm.gp_value,
@ -394,7 +392,7 @@ public:
// Add the symbol to the symbol map for debugging.
char temp[256];
sprintf(temp,"zz_%s", GetFuncName(func.moduleName, func.nid));
snprintf(temp, sizeof(temp), "zz_%s", GetFuncName(func.moduleName, func.nid));
g_symbolMap->AddFunction(temp,func.stubAddr,8);
// Keep track and actually hook it up if possible.

View File

@ -140,7 +140,7 @@ public:
static const char *GetStaticTypeName() { return "CallBack"; }
void GetQuickInfo(char *ptr, int size) override {
sprintf(ptr, "thread=%i, argument= %08x",
snprintf(ptr, size, "thread=%i, argument= %08x",
//hackAddress,
nc.threadId,
nc.commonArgument);
@ -378,7 +378,7 @@ public:
const char *GetTypeName() override { return GetStaticTypeName(); }
static const char *GetStaticTypeName() { return "Thread"; }
void GetQuickInfo(char *ptr, int size) override {
sprintf(ptr, "pc= %08x sp= %08x %s %s %s %s %s %s (wt=%i wid=%i wv= %08x )",
snprintf(ptr, size, "pc= %08x sp= %08x %s %s %s %s %s %s (wt=%i wid=%i wv= %08x )",
context.pc, context.r[MIPS_REG_SP],
(nt.status & THREADSTATUS_RUNNING) ? "RUN" : "",
(nt.status & THREADSTATUS_READY) ? "READY" : "",
@ -1699,7 +1699,7 @@ static void __ReportThreadQueueEmpty() {
idleThread0->GetQuickInfo(idleDescription0, sizeof(idleDescription0));
idleStatus0 = idleThread0->nt.status;
} else {
sprintf(idleDescription0, "DELETED");
truncate_cpy(idleDescription0, "DELETED");
}
char idleDescription1[256];
@ -1708,7 +1708,7 @@ static void __ReportThreadQueueEmpty() {
idleThread1->GetQuickInfo(idleDescription1, sizeof(idleDescription1));
idleStatus1 = idleThread1->nt.status;
} else {
sprintf(idleDescription1, "DELETED");
truncate_cpy(idleDescription1, "DELETED");
}
ERROR_LOG_REPORT_ONCE(threadqueueempty, Log::sceKernel, "Failed to reschedule: out of threads on queue (%d, %d)", idleStatus0, idleStatus1);