Fix for Qt GUI compiler warnings in iNesHeaderEditor for potential stack buffer overflows on snprintf usage.

This commit is contained in:
harry 2023-01-16 20:34:00 -05:00
parent f589dfed05
commit 38089b62c0
1 changed files with 10 additions and 7 deletions

View File

@ -695,8 +695,8 @@ bool iNesHeaderEditor_t::loadHeader(iNES_HEADER* header)
{ {
case errors::OPEN_FAILED: case errors::OPEN_FAILED:
{ {
char buf[2200]; char buf[5120];
sprintf(buf, "Error opening %s!", LoadedRomFName); snprintf(buf, sizeof(buf), "Error opening %s!", LoadedRomFName);
showErrorMsgWindow( buf ); showErrorMsgWindow( buf );
break; break;
} }
@ -737,8 +737,9 @@ bool iNesHeaderEditor_t::SaveINESFile(const char* path, iNES_HEADER* header)
FCEUFILE* source = FCEU_fopen(LoadedRomFName, NULL, "rb", 0, -1, ext); FCEUFILE* source = FCEU_fopen(LoadedRomFName, NULL, "rb", 0, -1, ext);
if (!source) if (!source)
{ {
sprintf(buf, "Opening source file %s failed.", LoadedRomFName); char msg[5120];
showErrorMsgWindow(buf); snprintf(msg, sizeof(msg), "Opening source file %s failed.", LoadedRomFName);
showErrorMsgWindow(msg);
return false; return false;
} }
@ -746,8 +747,9 @@ bool iNesHeaderEditor_t::SaveINESFile(const char* path, iNES_HEADER* header)
FILE* target = FCEUD_UTF8fopen(path, "wb"); FILE* target = FCEUD_UTF8fopen(path, "wb");
if (!target) if (!target)
{ {
sprintf(buf, "Creating target file %s failed.", path); char msg[5120];
showErrorMsgWindow(buf); snprintf(msg, sizeof(msg), "Creating target file %s failed.", path);
showErrorMsgWindow(msg);
return false; return false;
} }
@ -825,7 +827,8 @@ bool iNesHeaderEditor_t::openFile(void)
if ( GameInfo == NULL ) if ( GameInfo == NULL )
{ {
strcpy( LoadedRomFName, filename.toStdString().c_str() ); strncpy( LoadedRomFName, filename.toStdString().c_str(), sizeof(LoadedRomFName) );
LoadedRomFName[sizeof(LoadedRomFName)-1] = 0;
} }
return true; return true;