Debugger: replace sprintf() part 2 (PR #1085)

This commit is contained in:
Kelvin Lee 2022-04-17 20:40:21 +10:00 committed by GitHub
parent a5e8ee31a3
commit 494aaa04c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 45 deletions

View File

@ -751,7 +751,7 @@ Update_t CmdProfile (int nArgs)
{ {
if (! nArgs) if (! nArgs)
{ {
sprintf( g_aArgs[ 1 ].sArg, "%s", g_aParameters[ PARAM_RESET ].m_sName ); strncpy_s( g_aArgs[ 1 ].sArg, g_aParameters[ PARAM_RESET ].m_sName, _TRUNCATE );
nArgs = 1; nArgs = 1;
} }
@ -808,7 +808,7 @@ Update_t CmdProfile (int nArgs)
ConsoleBufferPushFormat( " Saved: %s", g_FileNameProfile.c_str() ); ConsoleBufferPushFormat( " Saved: %s", g_FileNameProfile.c_str() );
} }
else else
ConsoleBufferPush( TEXT(" ERROR: Couldn't save file. (In use?)" ) ); ConsoleBufferPush( " ERROR: Couldn't save file. (In use?)" );
} }
} }
} }
@ -3446,7 +3446,7 @@ bool MemoryDumpCheck (int nArgs, WORD * pAddress_ )
if (bUpdate) if (bUpdate)
{ {
pArg->nValue = nAddress; pArg->nValue = nAddress;
sprintf( pArg->sArg, "%04X", nAddress ); strncpy_s( pArg->sArg, WordToHexStr(nAddress).c_str(), _TRUNCATE );
} }
if (pAddress_) if (pAddress_)
@ -3863,8 +3863,7 @@ Update_t CmdMemoryLoad (int nArgs)
if (g_aArgs[ iArgComma1 ].eToken != TOKEN_COMMA) if (g_aArgs[ iArgComma1 ].eToken != TOKEN_COMMA)
return Help_Arg_1( CMD_MEMORY_SAVE ); return Help_Arg_1( CMD_MEMORY_SAVE );
TCHAR sLoadSaveFilePath[ MAX_PATH ]; std::string sLoadSaveFilePath = g_sCurrentDir; // TODO: g_sDebugDir
_tcscpy( sLoadSaveFilePath, g_sCurrentDir ); // TODO: g_sDebugDir
WORD nAddressStart; WORD nAddressStart;
WORD nAddress2 = 0; WORD nAddress2 = 0;
@ -3893,11 +3892,11 @@ Update_t CmdMemoryLoad (int nArgs)
if (bHaveFileName) if (bHaveFileName)
{ {
_tcscpy( g_sMemoryLoadSaveFileName, g_aArgs[ 1 ].sArg ); g_sMemoryLoadSaveFileName = g_aArgs[ 1 ].sArg;
} }
strcat( sLoadSaveFilePath, g_sMemoryLoadSaveFileName ); sLoadSaveFilePath += g_sMemoryLoadSaveFileName;
FILE *hFile = fopen( sLoadSaveFilePath, "rb" ); FILE *hFile = fopen( sLoadSaveFilePath.c_str(), "rb" );
if (hFile) if (hFile)
{ {
int nFileBytes = _GetFileSize( hFile ); int nFileBytes = _GetFileSize( hFile );
@ -3928,7 +3927,7 @@ Update_t CmdMemoryLoad (int nArgs)
CmdConfigGetDebugDir( 0 ); CmdConfigGetDebugDir( 0 );
ConsoleBufferPushFormat( "File: %s", g_sMemoryLoadSaveFileName ); ConsoleBufferPushFormat( "File: %s", g_sMemoryLoadSaveFileName.c_str() );
} }
delete [] pMemory; delete [] pMemory;
@ -4020,9 +4019,9 @@ Update_t CmdMemoryLoad (int nArgs)
const int nFileTypes = sizeof( aFileTypes ) / sizeof( KnownFileType_t ); const int nFileTypes = sizeof( aFileTypes ) / sizeof( KnownFileType_t );
const KnownFileType_t *pFileType = NULL; const KnownFileType_t *pFileType = NULL;
char *pFileName = g_aArgs[ 1 ].sArg; const char *pFileName = g_aArgs[ 1 ].sArg;
int nLen = strlen( pFileName ); int nLen = strlen( pFileName );
char *pEnd = pFileName + nLen - 1; const char *pEnd = pFileName + nLen - 1;
while ( pEnd > pFileName ) while ( pEnd > pFileName )
{ {
if ( *pEnd == '.' ) if ( *pEnd == '.' )
@ -4263,11 +4262,11 @@ Update_t CmdMemorySave (int nArgs)
{ {
if (! bHaveFileName) if (! bHaveFileName)
{ {
sprintf( g_sMemoryLoadSaveFileName, "%04X.%04X.bin", nAddressStart, nAddressLen ); // nAddressEnd ); g_sMemoryLoadSaveFileName = StrFormat( "%04X.%04X.bin", nAddressStart, nAddressLen ); // nAddressEnd );
} }
else else
{ {
_tcscpy( g_sMemoryLoadSaveFileName, g_aArgs[ 1 ].sArg ); g_sMemoryLoadSaveFileName = g_aArgs[ 1 ].sArg;
} }
strcat( sLoadSaveFilePath, g_sMemoryLoadSaveFileName ); strcat( sLoadSaveFilePath, g_sMemoryLoadSaveFileName );
@ -4413,12 +4412,9 @@ Update_t CmdMemorySave (int nArgs)
{ {
if (! bHaveFileName) if (! bHaveFileName)
{ {
TCHAR sMemoryLoadSaveFileName[MAX_PATH]; g_sMemoryLoadSaveFileName = (bBankSpecified)
if (! bBankSpecified) ? StrFormat( "%04X.%04X.bank%02X.bin", nAddressStart, nAddressLen, nBank )
sprintf( sMemoryLoadSaveFileName, "%04X.%04X.bin", nAddressStart, nAddressLen ); : StrFormat( "%04X.%04X.bin", nAddressStart, nAddressLen );
else
sprintf( sMemoryLoadSaveFileName, "%04X.%04X.bank%02X.bin", nAddressStart, nAddressLen, nBank );
g_sMemoryLoadSaveFileName = sMemoryLoadSaveFileName;
} }
else else
{ {
@ -5048,7 +5044,6 @@ Update_t CmdNTSC (int nArgs)
bool bColorTV = (GetVideo().GetVideoType() == VT_COLOR_TV); bool bColorTV = (GetVideo().GetVideoType() == VT_COLOR_TV);
uint32_t* pChromaTable = NTSC_VideoGetChromaTable( false, bColorTV ); uint32_t* pChromaTable = NTSC_VideoGetChromaTable( false, bColorTV );
char aStatusText[ CONSOLE_WIDTH*2 ] = "Loaded";
//uint8_t* pTmp = (uint8_t*) pChromaTable; //uint8_t* pTmp = (uint8_t*) pChromaTable;
//*pTmp++ = 0xFF; // b //*pTmp++ = 0xFF; // b
@ -5109,10 +5104,12 @@ Update_t CmdNTSC (int nArgs)
else else
if (iParam == PARAM_LOAD) if (iParam == PARAM_LOAD)
{ {
std::string sStatusText;
FILE *pFile = fopen( sPaletteFilePath.c_str(), "rb" ); FILE *pFile = fopen( sPaletteFilePath.c_str(), "rb" );
if ( pFile ) if ( pFile )
{ {
strcpy( aStatusText, "Loaded" ); sStatusText = "Loaded";
// Get File Size // Get File Size
size_t nFileSize = _GetFileSize( pFile ); size_t nFileSize = _GetFileSize( pFile );
@ -5128,13 +5125,13 @@ Update_t CmdNTSC (int nArgs)
if (bmp.nBitsPerPixel != 32) if (bmp.nBitsPerPixel != 32)
{ {
strcpy( aStatusText, "Bitmap not 32-bit RGBA" ); sStatusText = "Bitmap not 32-bit RGBA";
goto _error; goto _error;
} }
if (bmp.nOffsetData > nFileSize) if (bmp.nOffsetData > nFileSize)
{ {
strcpy( aStatusText, "Bad BITMAP: Data > file size !?" ); sStatusText = "Bad BITMAP: Data > file size !?";
goto _error; goto _error;
} }
@ -5144,7 +5141,7 @@ Update_t CmdNTSC (int nArgs)
|| ((bmp.nWidthPixels == 16 ) && (bmp.nHeightPixels == 1)) || ((bmp.nWidthPixels == 16 ) && (bmp.nHeightPixels == 1))
)) ))
{ {
strcpy( aStatusText, "Bitmap not 64x256, 64x1, or 16x1" ); sStatusText = "Bitmap not 64x256, 64x1, or 16x1";
goto _error; goto _error;
} }
@ -5167,7 +5164,7 @@ Update_t CmdNTSC (int nArgs)
else else
if ( nFileSize != g_nChromaSize ) if ( nFileSize != g_nChromaSize )
{ {
sprintf( aStatusText, "Raw size != %d", 64*256*4 ); sStatusText = StrFormat( "Raw size != %d", 64 * 256 * 4 );
goto _error; goto _error;
} }
@ -5212,11 +5209,11 @@ _error:
} }
else else
{ {
strcpy( aStatusText, "File: " ); sStatusText = "File: ";
ConsoleBufferPush( TEXT( "Error couldn't open file for reading." ) ); ConsoleBufferPush( "Error couldn't open file for reading." );
} }
ConsoleFilename::update( aStatusText ); ConsoleFilename::update( sStatusText.c_str() );
} }
else else
return HelpLastCommand(); return HelpLastCommand();
@ -8635,7 +8632,7 @@ void DebugInitialize ()
{ {
doneAutoRun = true; doneAutoRun = true;
std::string pathname = g_sProgramDir + "DebuggerAutoRun.txt"; std::string pathname = g_sProgramDir + "DebuggerAutoRun.txt";
strcpy_s(g_aArgs[1].sArg, MAX_ARG_LEN, pathname.c_str()); strncpy_s(g_aArgs[1].sArg, MAX_ARG_LEN, pathname.c_str(), _TRUNCATE);
CmdOutputRun(1); CmdOutputRun(1);
} }

View File

@ -519,30 +519,25 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
void VerifyDebuggerCommandTable() void VerifyDebuggerCommandTable()
{ {
char sText[ CONSOLE_WIDTH * 2 ];
for (int iCmd = 0; iCmd < NUM_COMMANDS; iCmd++ ) for (int iCmd = 0; iCmd < NUM_COMMANDS; iCmd++ )
{ {
if ( g_aCommands[ iCmd ].iCommand != iCmd) if ( g_aCommands[ iCmd ].iCommand != iCmd)
{ {
sprintf( sText, "*** ERROR *** Enumerated Commands mis-matched at #%d!", iCmd ); std::string sText = StrFormat( "*** ERROR *** Enumerated Commands mis-matched at #%d!", iCmd );
GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK ); GetFrame().FrameMessageBox(sText.c_str(), "ERROR", MB_OK);
PostQuitMessage( 1 ); PostQuitMessage( 1 );
} }
} }
// _tcscmp
if (strcmp( g_aCommands[ NUM_COMMANDS ].m_sName, DEBUGGER__COMMANDS_VERIFY_TXT__)) if (strcmp( g_aCommands[ NUM_COMMANDS ].m_sName, DEBUGGER__COMMANDS_VERIFY_TXT__))
{ {
sprintf( sText, "*** ERROR *** Total Commands mis-matched!" ); GetFrame().FrameMessageBox("*** ERROR *** Total Commands mis-matched!", "ERROR", MB_OK);
GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK );
PostQuitMessage( 1 ); PostQuitMessage( 1 );
} }
if (strcmp( g_aParameters[ NUM_PARAMS ].m_sName, DEBUGGER__PARAMS_VERIFY_TXT__)) if (strcmp( g_aParameters[ NUM_PARAMS ].m_sName, DEBUGGER__PARAMS_VERIFY_TXT__))
{ {
sprintf( sText, "*** ERROR *** Total Parameters mis-matched!" ); GetFrame().FrameMessageBox("*** ERROR *** Total Parameters mis-matched!", "ERROR", MB_OK);
GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK );
PostQuitMessage( 2 ); PostQuitMessage( 2 );
} }
} }

View File

@ -767,13 +767,12 @@ void DisasmCalcTopFromCurAddress(bool bUpdateTop)
// Moving the cursor line around is not really a good idea, since we're breaking consistency paradigm for the user. // Moving the cursor line around is not really a good idea, since we're breaking consistency paradigm for the user.
// g_nDisasmCurLine = 0; // g_nDisasmCurLine = 0;
#if 0 // _DEBUG #if 0 // _DEBUG
TCHAR sText[CONSOLE_WIDTH * 2]; std::string sText = StrFormat("DisasmCalcTopFromCurAddress()\n"
sprintf(sText, TEXT("DisasmCalcTopFromCurAddress()\n" "\tTop: %04X\n"
"\tTop: %04X\n" "\tLen: %04X\n"
"\tLen: %04X\n" "\tMissed: %04X",
"\tMissed: %04X"),
g_nDisasmCurAddress - nLen, nLen, g_nDisasmCurAddress); g_nDisasmCurAddress - nLen, nLen, g_nDisasmCurAddress);
GetFrame().FrameMessageBox(sText, "ERROR", MB_OK); GetFrame().FrameMessageBox(sText.c_str(), "ERROR", MB_OK);
#endif #endif
} }
} }

View File

@ -924,7 +924,7 @@ Update_t _CmdSymbolsUpdate( int nArgs, int bSymbolTables )
bSymbolTables = SYMBOL_TABLE_USER_2; // Autogenerated symbol names go in table 2 for organization when reverse engineering. Table 1 = known, Table 2 = unknown. bSymbolTables = SYMBOL_TABLE_USER_2; // Autogenerated symbol names go in table 2 for organization when reverse engineering. Table 1 = known, Table 2 = unknown.
nAddress = g_aArgs[2].nValue; nAddress = g_aArgs[2].nValue;
sprintf( g_aArgs[1].sArg, "_%04X", nAddress ); // Autogenerated symbol name strncpy_s( g_aArgs[1].sArg, StrFormat("_%04X", nAddress).c_str(), _TRUNCATE ); // Autogenerated symbol name
bUpdateSymbol = true; bUpdateSymbol = true;
} }