Debugger: Track remaining buffer size for snprintf to prevent fortify fail

This commit is contained in:
Ty Lamontagne 2024-08-06 16:29:53 -04:00 committed by Ty
parent deb8e5bf18
commit 112d02eaf5
1 changed files with 3 additions and 2 deletions

View File

@ -53,6 +53,7 @@ static void parseDisasm(SymbolMap& map, const char* disasm, char* opcode, char*
return;
}
char* arguments_start = arguments;
const char* jumpAddress = strstr(disasm,"->$");
const char* jumpRegister = strstr(disasm,"->");
while (*disasm != 0)
@ -66,9 +67,9 @@ static void parseDisasm(SymbolMap& map, const char* disasm, char* opcode, char*
const std::string addressSymbol = map.GetLabelName(branchTarget);
if (!addressSymbol.empty() && insertSymbols)
{
arguments += std::snprintf(arguments, arguments_size, "%s",addressSymbol.c_str());
arguments += std::snprintf(arguments, arguments_size - (arguments - arguments_start), "%s",addressSymbol.c_str());
} else {
arguments += std::snprintf(arguments, arguments_size, "0x%08X",branchTarget);
arguments += std::snprintf(arguments, arguments_size - (arguments - arguments_start), "0x%08X",branchTarget);
}
disasm += 3+2+8;