diff --git a/src/asm.cpp b/src/asm.cpp index 0aa2a61e..1c57d93b 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -286,7 +286,7 @@ char *Disassemble(int addr, uint8 *opcode) { #ifdef BRK_3BYTE_HACK case 0x00: - sprintf(str,"BRK %02X %02X", opcode[1], opcode[2]); + snprintf(str, sizeof(str), "BRK %02X %02X", opcode[1], opcode[2]); break; #else case 0x00: strcpy(str,"BRK"); break; @@ -333,7 +333,7 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xE1: strcpy(chr,"SBC"); goto _indirectx; _indirectx: indirectX(tmp); - sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + snprintf(str, sizeof(str), "%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); break; //Zero Page @@ -361,7 +361,7 @@ char *Disassemble(int addr, uint8 *opcode) { _zeropage: // ################################## Start of SP CODE ########################### // Change width to %04X // don't! - sprintf(str,"%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1])); + snprintf(str, sizeof(str), "%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1])); // ################################## End of SP CODE ########################### break; @@ -379,7 +379,7 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xE0: strcpy(chr,"CPX"); goto _immediate; case 0xE9: strcpy(chr,"SBC"); goto _immediate; _immediate: - sprintf(str,"%s #$%02X", chr,opcode[1]); + snprintf(str, sizeof(str), "%s #$%02X", chr,opcode[1]); break; //Absolute @@ -406,7 +406,7 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xEE: strcpy(chr,"INC"); goto _absolute; _absolute: absolute(tmp); - sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp)); + snprintf(str, sizeof(str), "%s $%04X = #$%02X", chr,tmp,GetMem(tmp)); break; //branches @@ -420,7 +420,7 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xF0: strcpy(chr,"BEQ"); goto _branch; _branch: relative(tmp); - sprintf(str,"%s $%04X", chr,tmp); + snprintf(str, sizeof(str), "%s $%04X", chr,tmp); break; //(Indirect),Y @@ -434,7 +434,7 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xF1: strcpy(chr,"SBC"); goto _indirecty; _indirecty: indirectY(tmp); - sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + snprintf(str, sizeof(str), "%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); break; //Zero Page,X @@ -458,7 +458,7 @@ char *Disassemble(int addr, uint8 *opcode) { zpIndex(tmp,RX); // ################################## Start of SP CODE ########################### // Change width to %04X // don't! - sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + snprintf(str, sizeof(str), "%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); // ################################## End of SP CODE ########################### break; @@ -475,7 +475,7 @@ char *Disassemble(int addr, uint8 *opcode) { _absolutey: absolute(tmp); tmp2=(tmp+RY); - sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); + snprintf(str, sizeof(str), "%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); break; //Absolute,X @@ -497,16 +497,16 @@ char *Disassemble(int addr, uint8 *opcode) { _absolutex: absolute(tmp); tmp2=(tmp+RX); - sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); + snprintf(str, sizeof(str), "%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); break; //jumps case 0x20: strcpy(chr,"JSR"); goto _jump; case 0x4C: strcpy(chr,"JMP"); goto _jump; - case 0x6C: absolute(tmp); sprintf(str,"JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break; + case 0x6C: absolute(tmp); snprintf(str, sizeof(str), "JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break; _jump: absolute(tmp); - sprintf(str,"%s $%04X", chr,tmp); + snprintf(str, sizeof(str), "%s $%04X", chr,tmp); break; //Zero Page,Y @@ -516,7 +516,7 @@ char *Disassemble(int addr, uint8 *opcode) { zpIndex(tmp,RY); // ################################## Start of SP CODE ########################### // Change width to %04X // don't! - sprintf(str,"%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + snprintf(str, sizeof(str), "%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); // ################################## End of SP CODE ########################### break; diff --git a/src/drivers/Qt/AboutWindow.cpp b/src/drivers/Qt/AboutWindow.cpp index 20719222..2ea28c7b 100644 --- a/src/drivers/Qt/AboutWindow.cpp +++ b/src/drivers/Qt/AboutWindow.cpp @@ -130,7 +130,7 @@ AboutWindow::AboutWindow(QWidget *parent) mainLayout->addLayout( hbox1 ); - sprintf( stmp, "git URL: %s", fceu_get_git_url() ); + snprintf( stmp, sizeof(stmp), "git URL: %s", fceu_get_git_url() ); hbox1 = new QHBoxLayout(); lbl = new QLabel( tr(stmp) ); @@ -140,7 +140,7 @@ AboutWindow::AboutWindow(QWidget *parent) mainLayout->addLayout( hbox1 ); - sprintf( stmp, "git Revision: %s", fceu_get_git_rev() ); + snprintf( stmp, sizeof(stmp), "git Revision: %s", fceu_get_git_rev() ); hbox1 = new QHBoxLayout(); lbl = new QLabel( tr(stmp) ); @@ -191,23 +191,23 @@ AboutWindow::AboutWindow(QWidget *parent) credits->insertPlainText( "\nOpen Source Dependencies:\n" ); - sprintf( stmp, " Compiled with Qt version %d.%d.%d\n", QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH ); + snprintf( stmp, sizeof(stmp), " Compiled with Qt version %d.%d.%d\n", QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH ); credits->insertPlainText( stmp ); - sprintf( stmp, " Compiled with SDL version %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL ); + snprintf( stmp, sizeof(stmp), " Compiled with SDL version %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL ); credits->insertPlainText( stmp ); SDL_version v; SDL_GetVersion(&v); - sprintf( stmp, " Linked with SDL version %d.%d.%d\n", v.major, v.minor, v.patch); + snprintf( stmp, sizeof(stmp), " Linked with SDL version %d.%d.%d\n", v.major, v.minor, v.patch); credits->insertPlainText( stmp ); #ifdef ZLIB_VERSION - sprintf( stmp, " Compiled with zlib %s\n", ZLIB_VERSION ); + snprintf( stmp, sizeof(stmp), " Compiled with zlib %s\n", ZLIB_VERSION ); credits->insertPlainText( stmp ); #endif #ifdef _USE_LIBARCHIVE - sprintf( stmp, " Compiled with libarchive %s\n", ARCHIVE_VERSION_ONLY_STRING ); + snprintf( stmp, sizeof(stmp), " Compiled with libarchive %s\n", ARCHIVE_VERSION_ONLY_STRING ); credits->insertPlainText( stmp ); const char *libArcName[] = { "zlib", "liblzma", "bzlib", "liblz4", "libzstd", nullptr }; const char *libArcVersion[] = { archive_zlib_version(), archive_liblzma_version(), @@ -217,7 +217,7 @@ AboutWindow::AboutWindow(QWidget *parent) { if (libArcVersion[i]) { - sprintf( stmp, " %s %s\n", libArcName[i], libArcVersion[i]); + snprintf( stmp, sizeof(stmp), " %s %s\n", libArcName[i], libArcVersion[i]); credits->insertPlainText( stmp ); } i++; @@ -225,27 +225,27 @@ AboutWindow::AboutWindow(QWidget *parent) #endif #ifdef _S9XLUA_H - sprintf( stmp, " Compiled with %s\n", LUA_RELEASE ); + snprintf( stmp, sizeof(stmp), " Compiled with %s\n", LUA_RELEASE ); credits->insertPlainText( stmp ); #endif #ifdef _USE_LIBAV - sprintf( stmp, " Compiled with ffmpeg libraries:\n"); + snprintf( stmp, sizeof(stmp), " Compiled with ffmpeg libraries:\n"); credits->insertPlainText( stmp ); - sprintf( stmp, " libavutil %i.%i.%i\n", LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO); + snprintf( stmp, sizeof(stmp), " libavutil %i.%i.%i\n", LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO); credits->insertPlainText( stmp ); - sprintf( stmp, " libavformat %i.%i.%i\n", LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO); + snprintf( stmp, sizeof(stmp), " libavformat %i.%i.%i\n", LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO); credits->insertPlainText( stmp ); - sprintf( stmp, " libavcodec %i.%i.%i\n", LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO); + snprintf( stmp, sizeof(stmp), " libavcodec %i.%i.%i\n", LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO); credits->insertPlainText( stmp ); - sprintf( stmp, " libswscale %i.%i.%i\n", LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO); + snprintf( stmp, sizeof(stmp), " libswscale %i.%i.%i\n", LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO); credits->insertPlainText( stmp ); - sprintf( stmp, " libswresample %i.%i.%i\n", LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR, LIBSWRESAMPLE_VERSION_MICRO); + snprintf( stmp, sizeof(stmp), " libswresample %i.%i.%i\n", LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR, LIBSWRESAMPLE_VERSION_MICRO); credits->insertPlainText( stmp ); #endif #ifdef _USE_X264 - sprintf( stmp, " Compiled with x264 version %s\n", X264_POINTVER ); + snprintf( stmp, sizeof(stmp), " Compiled with x264 version %s\n", X264_POINTVER ); credits->insertPlainText( stmp ); #endif diff --git a/src/drivers/Qt/AviRecord.cpp b/src/drivers/Qt/AviRecord.cpp index 213d7106..d6a57e1b 100644 --- a/src/drivers/Qt/AviRecord.cpp +++ b/src/drivers/Qt/AviRecord.cpp @@ -795,7 +795,7 @@ struct OutputStream if ( writeError ) { char msg[512]; - sprintf( msg, "%s Stream Write Errors Detected.\nOutput may be incomplete or corrupt.\nSee log file '%s' for details\n", + snprintf( msg, sizeof(msg), "%s Stream Write Errors Detected.\nOutput may be incomplete or corrupt.\nSee log file '%s' for details\n", isAudio ? "Audio" : "Video", AV_LOG_FILE_NAME); FCEUD_PrintError(msg); } @@ -2123,7 +2123,7 @@ int aviRecordLogOpen(void) if ( avLogFp == NULL ) { char msg[512]; - sprintf( msg, "Error: Failed to open AV Recording log file for writing: %s\n", AV_LOG_FILE_NAME); + snprintf( msg, sizeof(msg), "Error: Failed to open AV Recording log file for writing: %s\n", AV_LOG_FILE_NAME); FCEUD_PrintError(msg); avLogFp = stdout; } @@ -2224,7 +2224,7 @@ int aviRecordOpenFile( const char *filepath ) avi_info.add_pair( "IMED", QSysInfo::prettyProductName().toLocal8Bit().constData() ); - sprintf( txt, "FCEUX %s", FCEU_VERSION_STRING ); + snprintf( txt, sizeof(txt), "FCEUX %s", FCEU_VERSION_STRING ); avi_info.add_pair( "ITCH", txt ); romFile = getRomFile(); @@ -2305,7 +2305,7 @@ int aviRecordOpenFile( const char *filepath ) char msg[512]; fprintf( avLogFp, "Error: Failed to open AVI file.\n"); recordEnable = false; - sprintf( msg, "Error: AV Recording Initialization Failed.\nSee %s for details...\n", AV_LOG_FILE_NAME); + snprintf( msg, sizeof(msg), "Error: AV Recording Initialization Failed.\nSee %s for details...\n", AV_LOG_FILE_NAME); FCEUD_PrintError(msg); return -1; } @@ -2320,7 +2320,7 @@ int aviRecordOpenFile( const char *filepath ) char msg[512]; fprintf( avLogFp, "Error: Failed to open AVI file.\n"); recordEnable = false; - sprintf( msg, "Error: AV Recording Initialization Failed.\nSee %s for details...\n", AV_LOG_FILE_NAME); + snprintf( msg, sizeof(msg), "Error: AV Recording Initialization Failed.\nSee %s for details...\n", AV_LOG_FILE_NAME); FCEUD_PrintError(msg); return -1; } @@ -3136,7 +3136,7 @@ void LibavOptionsPage::initSampleRateSelect( const char *codec_name ) while ( c->supported_samplerates[i] != 0 ) { - sprintf( rateName, "%i", c->supported_samplerates[i] ); + snprintf( rateName, sizeof(rateName), "%i", c->supported_samplerates[i] ); audioSampleRate->addItem( tr(rateName), c->supported_samplerates[i] ); @@ -3410,7 +3410,7 @@ void LibavEncOptItem::setValueText(void) if ( units[x]->default_val.i64 & i ) { char stmp2[128]; - sprintf( stmp2, "%s", units[x]->name ); + snprintf( stmp2, sizeof(stmp2), "%s", units[x]->name ); if (j>0) { strcat( stmp, ","); @@ -3445,7 +3445,7 @@ void LibavEncOptItem::setValueText(void) if ( units[x]->default_val.i64 == i ) { char stmp2[128]; - sprintf( stmp2, " (%s)", units[x]->name ); + snprintf( stmp2, sizeof(stmp2), " (%s)", units[x]->name ); strcat( stmp, stmp2 ); break; } @@ -3481,12 +3481,12 @@ LibavEncOptWin::LibavEncOptWin(int type, QWidget *parent) if ( type ) { codec_name = LIBAV::audio_st.selEnc.c_str(); - sprintf( title, "%s Audio Encoder Configuration", codec_name ); + snprintf( title, sizeof(title), "%s Audio Encoder Configuration", codec_name ); } else { codec_name = LIBAV::video_st.selEnc.c_str(); - sprintf( title, "%s Video Encoder Configuration", codec_name ); + snprintf( title, sizeof(title), "%s Video Encoder Configuration", codec_name ); } setWindowTitle( title ); resize(512, 512); @@ -3816,13 +3816,13 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare grid->addWidget( new QLabel( tr("Range:") ), 2, 0 ); - sprintf( stmp, "[ %.0f, %.0f ]", opt->min, opt->max ); + snprintf( stmp, sizeof(stmp), "[ %.0f, %.0f ]", opt->min, opt->max ); grid->addWidget( new QLabel( tr(stmp) ), 2, 1 ); grid->addWidget( new QLabel( tr("Default:") ), 3, 0 ); - sprintf( stmp, "%lli", (long long)opt->default_val.i64 ); + snprintf( stmp, sizeof(stmp), "%lli", (long long)opt->default_val.i64 ); grid->addWidget( new QLabel( tr(stmp) ), 3, 1 ); @@ -3838,12 +3838,12 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare { if ( item->units[i]->help ) { - sprintf( stmp, "%3lli: %s - %s", (long long)item->units[i]->default_val.i64, + snprintf( stmp, sizeof(stmp), "%3lli: %s - %s", (long long)item->units[i]->default_val.i64, item->units[i]->name, item->units[i]->help ); } else { - sprintf( stmp, "%3lli: %s", (long long)item->units[i]->default_val.i64, + snprintf( stmp, sizeof(stmp), "%3lli: %s", (long long)item->units[i]->default_val.i64, item->units[i]->name ); } @@ -3874,13 +3874,13 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare grid->addWidget( new QLabel( tr("Range:") ), 2, 0 ); - sprintf( stmp, "[ %e, %e ]", opt->min, opt->max ); + snprintf( stmp, sizeof(stmp), "[ %e, %e ]", opt->min, opt->max ); grid->addWidget( new QLabel( tr(stmp) ), 2, 1 ); grid->addWidget( new QLabel( tr("Default:") ), 3, 0 ); - sprintf( stmp, "%f", opt->default_val.dbl ); + snprintf( stmp, sizeof(stmp), "%f", opt->default_val.dbl ); grid->addWidget( new QLabel( tr(stmp) ), 3, 1 ); @@ -3905,7 +3905,7 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare if ( opt->default_val.str ) { - sprintf( stmp, "%s", opt->default_val.str ); + snprintf( stmp, sizeof(stmp), "%s", opt->default_val.str ); } grid->addWidget( new QLabel( tr(stmp) ), 2, 1 ); @@ -3929,7 +3929,7 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare grid->addWidget( new QLabel( tr("Default:") ), 2, 0 ); - sprintf( stmp, "%i/%i", opt->default_val.q.num, opt->default_val.q.den ); + snprintf( stmp, sizeof(stmp), "%i/%i", opt->default_val.q.num, opt->default_val.q.den ); grid->addWidget( new QLabel( tr(stmp) ), 2, 1 ); @@ -3959,7 +3959,7 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare grid->addWidget( new QLabel( tr("Default:") ), 2, 0 ); - sprintf( stmp, "%s", opt->default_val.i64 ? "true" : "false" ); + snprintf( stmp, sizeof(stmp), "%s", opt->default_val.i64 ? "true" : "false" ); grid->addWidget( new QLabel( tr(stmp) ), 2, 1 ); @@ -3983,7 +3983,7 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare grid->addWidget( new QLabel( tr("Default:") ), 2, 0 ); - sprintf( stmp, "0x%08llX", (unsigned long long)opt->default_val.i64 ); + snprintf( stmp, sizeof(stmp), "0x%08llX", (unsigned long long)opt->default_val.i64 ); grid->addWidget( new QLabel( tr(stmp) ), 2, 1 ); @@ -3993,7 +3993,7 @@ LibavEncOptInputWin::LibavEncOptInputWin( LibavEncOptItem *itemIn, QWidget *pare for (size_t i=0; iunits.size(); i++) { - sprintf( stmp, "%s", item->units[i]->name ); + snprintf( stmp, sizeof(stmp), "%s", item->units[i]->name ); c = new QCheckBox( tr(stmp) ); diff --git a/src/drivers/Qt/AviRiffViewer.cpp b/src/drivers/Qt/AviRiffViewer.cpp index 5635261a..0260efd1 100644 --- a/src/drivers/Qt/AviRiffViewer.cpp +++ b/src/drivers/Qt/AviRiffViewer.cpp @@ -475,112 +475,112 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) avi->getChunkData( item->filePos(), data.buf, item->getSize()+8 ); - sprintf( stmp, "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("fcc") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(4) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(4) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("cb") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(8) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(8) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwMicroSecPerFrame") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(12) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(12) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwMaxBytesPerSec") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(16) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(16) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwPaddingGranularity") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "0x%X", data.readU32(20) ); + snprintf( stmp, sizeof(stmp), "0x%X", data.readU32(20) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwFlags") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(24) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(24) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwTotalFrames") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(28) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(28) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwInitialFrames") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(32) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(32) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwStreams") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(36) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(36) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwSuggestedBufferSize") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(40) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(40) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwWidth") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(44) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(44) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwHeight") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(48) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(48) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwScale") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(52) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(52) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwRate") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(56) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(56) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwStart") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(60) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(60) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwLength") ); @@ -593,21 +593,21 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) avi->getChunkData( item->filePos(), data.buf, item->getSize()+8 ); - sprintf( stmp, "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("fcc") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(4) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(4) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("cb") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%c%c%c%c", data.buf[8], data.buf[9], data.buf[10], data.buf[11] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[8], data.buf[9], data.buf[10], data.buf[11] ); strcpy( strhType, stmp ); twi = new QTreeWidgetItem(); @@ -617,11 +617,11 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) if ( isalnum(data.buf[12]) ) { - sprintf( stmp, "%c%c%c%c", data.buf[12], data.buf[13], data.buf[14], data.buf[15] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[12], data.buf[13], data.buf[14], data.buf[15] ); } else { - sprintf( stmp, "0x%X", data.readU32(12) ); + snprintf( stmp, sizeof(stmp), "0x%X", data.readU32(12) ); } twi = new QTreeWidgetItem(); @@ -629,42 +629,42 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "0x%X", data.readU32(16) ); + snprintf( stmp, sizeof(stmp), "0x%X", data.readU32(16) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwFlags") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(20) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(20) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("wPriority") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(22) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(22) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("wLanguage") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(24) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(24) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwInitialFrames") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(28) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(28) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwScale") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(32) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(32) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwRate") ); @@ -672,68 +672,68 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) if ( strcmp( strhType, "vids" ) == 0 ) { - sprintf( stmp, "(%13.10f Hz)", (double)data.readU32(32) / (double)data.readU32(28) ); + snprintf( stmp, sizeof(stmp), "(%13.10f Hz)", (double)data.readU32(32) / (double)data.readU32(28) ); twi->setText( 3, tr(stmp) ); } item->addChild(twi); - sprintf( stmp, "%u", data.readU32(36) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(36) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwStart") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(40) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(40) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwLength") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(44) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(44) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwSuggestedBufferSize") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%i", data.readI32(48) ); + snprintf( stmp, sizeof(stmp), "%i", data.readI32(48) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwQuality") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(52) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(52) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("dwSampleSize") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(56) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(56) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("rcFrame.left") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(58) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(58) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("rcFrame.top") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(60) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(60) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("rcFrame.right") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(62) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(62) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("rcFrame.bottom") ); @@ -748,49 +748,49 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) avi->getChunkData( item->filePos(), data.buf, item->getSize()+8 ); - sprintf( stmp, "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("fcc") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(4) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(4) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("cb") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(8) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(8) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biSize") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%i", data.readI32(12) ); + snprintf( stmp, sizeof(stmp), "%i", data.readI32(12) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biWidth") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%i", data.readI32(16) ); + snprintf( stmp, sizeof(stmp), "%i", data.readI32(16) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biHeight") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(20) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(20) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biPlanes") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(22) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(22) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biBitCount") ); @@ -799,11 +799,11 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) if ( isalnum(data.buf[24]) ) { - sprintf( stmp, "%c%c%c%c", data.buf[24], data.buf[25], data.buf[26], data.buf[27] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[24], data.buf[25], data.buf[26], data.buf[27] ); } else { - sprintf( stmp, "0x%X", data.readU32(24) ); + snprintf( stmp, sizeof(stmp), "0x%X", data.readU32(24) ); } twi = new QTreeWidgetItem(); @@ -811,35 +811,35 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(28) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(28) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biSizeImage") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%i", data.readI32(32) ); + snprintf( stmp, sizeof(stmp), "%i", data.readI32(32) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biXPelsPerMeter") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%i", data.readI32(36) ); + snprintf( stmp, sizeof(stmp), "%i", data.readI32(36) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biYPelsPerMeter") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(40) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(40) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biClrUsed") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(44) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(44) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("biClrImportant") ); @@ -854,56 +854,56 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) avi->getChunkData( item->filePos(), data.buf, dataSize ); - sprintf( stmp, "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("fcc") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(4) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(4) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("cb") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(8) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(8) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("wFormatTag") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(10) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(10) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("nChannels") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(12) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(12) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("nSamplesPerSec") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(16) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(16) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("nAvgBytesPerSec") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(20) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(20) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("nBlockAlign") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU16(22) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU16(22) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("nBitsPerSample") ); @@ -929,21 +929,21 @@ int AviRiffViewerDialog::processChunk( AviRiffTreeItem *item ) avi->getChunkData( item->filePos(), data.buf, item->getSize()+8 ); - sprintf( stmp, "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); + snprintf( stmp, sizeof(stmp), "%c%c%c%c", data.buf[0], data.buf[1], data.buf[2], data.buf[3] ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("fcc") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(4) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(4) ); twi = new QTreeWidgetItem(); twi->setText( 0, tr("cb") ); twi->setText( 2, tr(stmp) ); item->addChild(twi); - sprintf( stmp, "%u", data.readU32(8) ); + snprintf( stmp, sizeof(stmp), "%u", data.readU32(8) ); for (i=0; i < static_cast(item->getSize()); i++) { @@ -991,7 +991,7 @@ AviRiffTreeItem::AviRiffTreeItem(int typeIn, long long int fposIn, const char *f strcpy( fourcc, fourccIn ); - //sprintf( stmp, "0x%08llX", fposIn ); + //snprintf( stmp, sizeof(stmp), "0x%08llX", fposIn ); switch ( type ) { @@ -1013,16 +1013,16 @@ AviRiffTreeItem::AviRiffTreeItem(int typeIn, long long int fposIn, const char *f if ( showSizeHex ) { - sprintf( stmp, "0x%08lX", (unsigned long)size ); + snprintf( stmp, sizeof(stmp), "0x%08lX", (unsigned long)size ); } else { - sprintf( stmp, "%zu", size ); + snprintf( stmp, sizeof(stmp), "%zu", size ); } setText( 2, QString(stmp) ); - sprintf( stmp, "0x%08llX", fposIn ); + snprintf( stmp, sizeof(stmp), "0x%08llX", fposIn ); setText( 3, QString(stmp) ); } diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 31d2585b..638d82f3 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -517,9 +517,9 @@ int GuiCheatsDialog_t::addSearchResult(uint32_t a, uint8_t last, uint8_t current item = new QTreeWidgetItem(); - sprintf(addrStr, "$%04X", a); - sprintf(lastStr, "%02X", last); - sprintf(curStr, "%02X", current); + snprintf(addrStr, sizeof(addrStr), "$%04X", a); + snprintf(lastStr, sizeof(lastStr), "%02X", last); + snprintf(curStr, sizeof(curStr), "%02X", current); //item->setFont( 0, font ); //item->setFont( 1, font ); @@ -693,11 +693,11 @@ int GuiCheatsDialog_t::activeCheatListCB(const char *name, uint32 a, uint8 v, in if (c >= 0) { - sprintf(codeStr, "$%04X?%02X:%02X", a, c, v); + snprintf(codeStr, sizeof(codeStr), "$%04X?%02X:%02X", a, c, v); } else { - sprintf(codeStr, "$%04X:%02X ", a, v); + snprintf(codeStr, sizeof(codeStr), "$%04X:%02X ", a, v); } item = actvCheatList->topLevelItem(actvCheatIdx); @@ -834,7 +834,7 @@ void GuiCheatsDialog_t::saveCheatFile(void) dialog.selectFile(dir); } - sprintf(dir, "%s/cheats", FCEUI_GetBaseDirectory()); + snprintf(dir, sizeof(dir), "%s/cheats", FCEUI_GetBaseDirectory()); dialog.setDirectory(tr(dir)); @@ -1025,15 +1025,15 @@ void GuiCheatsDialog_t::actvCheatItemClicked(QTreeWidgetItem *item, int column) FCEUI_ToggleCheat(row); } } - sprintf(stmp, "%04X", a); + snprintf(stmp, sizeof(stmp), "%04X", a); cheatAddrEntry->setText(tr(stmp)); - sprintf(stmp, "%02X", v); + snprintf(stmp, sizeof(stmp), "%02X", v); cheatValEntry->setText(tr(stmp)); if (c >= 0) { - sprintf(stmp, "%02X", c); + snprintf(stmp, sizeof(stmp), "%02X", c); cheatCmpEntry->setText(tr(stmp)); } else diff --git a/src/drivers/Qt/CodeDataLogger.cpp b/src/drivers/Qt/CodeDataLogger.cpp index 6db21778..808f015a 100644 --- a/src/drivers/Qt/CodeDataLogger.cpp +++ b/src/drivers/Qt/CodeDataLogger.cpp @@ -364,22 +364,22 @@ void CodeDataLoggerDialog_t::updatePeriodic(void) if (cdloggerdataSize > 0) { - sprintf(str, "0x%06x %.2f%%", codecount, (fcodecount / fromsize) * 100); + snprintf(str, sizeof(str), "0x%06x %.2f%%", codecount, (fcodecount / fromsize) * 100); prgLoggedCodeLabel->setText(tr(str)); - sprintf(str, "0x%06x %.2f%%", datacount, (fdatacount / fromsize) * 100); + snprintf(str, sizeof(str), "0x%06x %.2f%%", datacount, (fdatacount / fromsize) * 100); prgLoggedDataLabel->setText(tr(str)); - sprintf(str, "0x%06x %.2f%%", undefinedcount, (fundefinedcount / fromsize) * 100); + snprintf(str, sizeof(str), "0x%06x %.2f%%", undefinedcount, (fundefinedcount / fromsize) * 100); prgUnloggedLabel->setText(tr(str)); - sprintf(str, "0x%06x %.2f%%", rendercount, (frendercount / fvromsize) * 100); + snprintf(str, sizeof(str), "0x%06x %.2f%%", rendercount, (frendercount / fvromsize) * 100); chrLoggedCodeLabel->setText(tr(str)); - sprintf(str, "0x%06x %.2f%%", vromreadcount, (fvromreadcount / fvromsize) * 100); + snprintf(str, sizeof(str), "0x%06x %.2f%%", vromreadcount, (fvromreadcount / fvromsize) * 100); chrLoggedDataLabel->setText(tr(str)); - sprintf(str, "0x%06x %.2f%%", undefinedvromcount, (fundefinedvromcount / fvromsize) * 100); + snprintf(str, sizeof(str), "0x%06x %.2f%%", undefinedvromcount, (fundefinedvromcount / fvromsize) * 100); chrUnloggedLabel->setText(tr(str)); } else @@ -392,7 +392,7 @@ void CodeDataLoggerDialog_t::updatePeriodic(void) chrUnloggedLabel->setText(tr("------")); } - sprintf(str, "CDL File: %s", loadedcdfile); + snprintf(str, sizeof(str), "CDL File: %s", loadedcdfile); cdlFileLabel->setText(tr(str)); } diff --git a/src/drivers/Qt/ColorMenu.cpp b/src/drivers/Qt/ColorMenu.cpp index dd1a6f20..edcc440c 100644 --- a/src/drivers/Qt/ColorMenu.cpp +++ b/src/drivers/Qt/ColorMenu.cpp @@ -167,7 +167,7 @@ ColorMenuPickerDialog_t::ColorMenuPickerDialog_t( QColor *c, const char *titleTe style = this->style(); - sprintf( stmp, "Pick Color for %s", titleText); + snprintf( stmp, sizeof(stmp), "Pick Color for %s", titleText); setWindowTitle( stmp ); diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 3b11c133..3eddf2d1 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -150,7 +150,7 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent) tabView[i][j] = new DebuggerTabWidget(i,j); - sprintf( stmp, "debuggerTabView%i%i\n", i+1, j+1 ); + snprintf( stmp, sizeof(stmp), "debuggerTabView%i%i\n", i+1, j+1 ); tabView[i][j]->setObjectName( tr(stmp) ); @@ -1553,7 +1553,7 @@ void ConsoleDebugger::loadDisplayViews(void) for (int j=0; j<4; j++) { QString tabListVal; - sprintf( key, "debugger/tabView%i%i", i+1, j+1 ); + snprintf( key, sizeof(key), "debugger/tabView%i%i", i+1, j+1 ); tabListVal = settings.value(key).toString(); QStringList tabList = tabListVal.split(','); @@ -1610,7 +1610,7 @@ void ConsoleDebugger::loadDisplayViews(void) // Save Vertical Panel State for (int i=0; i<2; i++) { - sprintf( key, "debugger/vPanelState%i", i+1); + snprintf( key, sizeof(key), "debugger/vPanelState%i", i+1); vsplitter[i]->restoreState( settings.value(key).toByteArray() ); } @@ -1628,7 +1628,7 @@ void ConsoleDebugger::saveDisplayViews(void) for (int j=0; j<4; j++) { QString tabListVal; - sprintf( key, "debugger/tabView%i%i", i+1, j+1 ); + snprintf( key, sizeof(key), "debugger/tabView%i%i", i+1, j+1 ); for (int k=0; kcount(); k++) { @@ -1650,7 +1650,7 @@ void ConsoleDebugger::saveDisplayViews(void) // Save Vertical Panel State for (int i=0; i<2; i++) { - sprintf( key, "debugger/vPanelState%i", i+1); + snprintf( key, sizeof(key), "debugger/vPanelState%i", i+1); settings.setValue( key, vsplitter[i]->saveState()); } @@ -1981,13 +1981,13 @@ DebuggerBreakpointEditor::DebuggerBreakpointEditor(int editIndex, watchpointinfo rom_radio->setChecked(true); } - sprintf( stmp, "%04X", wp->address ); + snprintf( stmp, sizeof(stmp), "%04X", wp->address ); addr1->setText( tr(stmp) ); if ( wp->endaddress > 0 ) { - sprintf( stmp, "%04X", wp->endaddress ); + snprintf( stmp, sizeof(stmp), "%04X", wp->endaddress ); addr2->setText( tr(stmp) ); } @@ -2032,14 +2032,14 @@ DebuggerBreakpointEditor::DebuggerBreakpointEditor(int editIndex, watchpointinfo if ( romAddr >= 0 ) { wp->address = romAddr; - sprintf( stmp, "%X", wp->address ); + snprintf( stmp, sizeof(stmp), "%X", wp->address ); addr1->setText( tr(stmp) ); rom_radio->setChecked(true); } else { char str[64]; - sprintf(str, "K==#%02X", getBank(wp->address)); + snprintf(str, sizeof(str), "K==#%02X", getBank(wp->address)); cond->setText( tr(str) ); } } @@ -2388,11 +2388,11 @@ void ConsoleDebugger::bpListUpdate( bool reset ) if ( watchpoint[i].endaddress > 0 ) { - sprintf( addrStr, "$%04X-%04X:", watchpoint[i].address, watchpoint[i].endaddress ); + snprintf( addrStr, sizeof(addrStr), "$%04X-%04X:", watchpoint[i].address, watchpoint[i].endaddress ); } else { - sprintf( addrStr, "$%04X:", watchpoint[i].address ); + snprintf( addrStr, sizeof(addrStr), "$%04X:", watchpoint[i].address ); } flags[0] = (watchpoint[i].flags & WP_E) ? 'E' : '-'; @@ -2519,7 +2519,7 @@ void ConsoleDebugger::edit_BM_name( int addr ) bm = dbgBmMgr.getAddr( addr ); - sprintf( stmp, "Specify Bookmark Name for %04X", addr ); + snprintf( stmp, sizeof(stmp), "Specify Bookmark Name for %04X", addr ); dialog.setWindowTitle( tr("Edit Bookmark") ); dialog.setLabelText( tr(stmp) ); @@ -2571,7 +2571,7 @@ void ConsoleDebugger::bmListUpdate( bool reset ) bmTree->addTopLevelItem( item ); } - sprintf( addrStr, "%04X", bm->addr ); + snprintf( addrStr, sizeof(addrStr), "%04X", bm->addr ); //item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable ); item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemNeverHasChildren ); @@ -3501,7 +3501,7 @@ void ConsoleDebugger::setBookmarkSelectedAddress( int addr ) { char stmp[32]; - sprintf( stmp, "%04X", addr ); + snprintf( stmp, sizeof(stmp), "%04X", addr ); selBmAddr->setText( tr(stmp) ); @@ -3947,16 +3947,16 @@ void QAsmView::updateAssemblyView(void) if (displayROMoffsets && (a->rom != -1) ) { - sprintf(chr, " %06X: ", a->rom); + snprintf(chr, sizeof(chr), " %06X: ", a->rom); } else { - sprintf(chr, "%02X:%04X: ", a->bank, addr); + snprintf(chr, sizeof(chr), "%02X:%04X: ", a->bank, addr); } } else { - sprintf(chr, " :%04X: ", addr); + snprintf(chr, sizeof(chr), " :%04X: ", addr); } line.append(chr); @@ -3964,7 +3964,7 @@ void QAsmView::updateAssemblyView(void) if (size == 0) { - sprintf(chr, "%02X UNDEFINED", GetMem(addr++)); + snprintf(chr, sizeof(chr), "%02X UNDEFINED", GetMem(addr++)); line.append(chr); } else @@ -3973,7 +3973,7 @@ void QAsmView::updateAssemblyView(void) { while (addr < 0xFFFF) { - sprintf(chr, "%02X OVERFLOW\n", GetMem(addr++)); + snprintf(chr, sizeof(chr), "%02X OVERFLOW\n", GetMem(addr++)); line.append(chr); } delete a; @@ -3981,7 +3981,7 @@ void QAsmView::updateAssemblyView(void) } for (int j = 0; j < size; j++) { - sprintf(chr, "%02X ", opcode[j] = GetMem(addr++)); + snprintf(chr, sizeof(chr), "%02X ", opcode[j] = GetMem(addr++)); if ( showByteCodes ) line.append(chr); } while (size < 3) @@ -4217,23 +4217,23 @@ void ConsoleDebugger::updateRegisterView(void) char stmp[64]; char str[32], str2[32]; - sprintf( stmp, "%04X", X.PC ); + snprintf( stmp, sizeof(stmp), "%04X", X.PC ); pcEntry->setText( tr(stmp) ); - sprintf( stmp, "%02X", X.A ); + snprintf( stmp, sizeof(stmp), "%02X", X.A ); regAEntry->setText( tr(stmp) ); - sprintf( stmp, "%02X", X.X ); + snprintf( stmp, sizeof(stmp), "%02X", X.X ); regXEntry->setText( tr(stmp) ); - sprintf( stmp, "%02X", X.Y ); + snprintf( stmp, sizeof(stmp), "%02X", X.Y ); regYEntry->setText( tr(stmp) ); - sprintf( stmp, "%02X", X.P ); + snprintf( stmp, sizeof(stmp), "%02X", X.P ); regPEntry->setText( tr(stmp) ); @@ -4248,7 +4248,7 @@ void ConsoleDebugger::updateRegisterView(void) stackPtr = X.S | 0x0100; - sprintf( stmp, "Stack: $%04X", stackPtr ); + snprintf( stmp, sizeof(stmp), "Stack: $%04X", stackPtr ); stackFrame->setTitle( tr(stmp) ); stackText->updateText(); @@ -4266,26 +4266,26 @@ void ConsoleDebugger::updateRegisterView(void) ResetDebugStatisticsCounters(); counter_value2 = 0; } - sprintf(stmp, "%10llu (+%llu)", counter_value1, counter_value2); + snprintf(stmp, sizeof(stmp), "%10llu (+%llu)", counter_value1, counter_value2); cpuCyclesVal->setText( tr(stmp) ); - sprintf(stmp, "%10llu (+%llu)", total_instructions, delta_instructions); + snprintf(stmp, sizeof(stmp), "%10llu (+%llu)", total_instructions, delta_instructions); cpuInstrsVal->setText( tr(stmp) ); // PPU Labels - sprintf(stmp, "$%02X", PPU[0] ); + snprintf(stmp, sizeof(stmp), "$%02X", PPU[0] ); ppuCtrlReg->setText( tr(stmp) ); - sprintf(stmp, "$%02X", PPU[1] ); + snprintf(stmp, sizeof(stmp), "$%02X", PPU[1] ); ppuMaskReg->setText( tr(stmp) ); - sprintf(stmp, "$%02X", PPU[2] ); + snprintf(stmp, sizeof(stmp), "$%02X", PPU[2] ); ppuStatReg->setText( tr(stmp) ); - sprintf(stmp, "$%04X", (int)FCEUPPU_PeekAddress()); + snprintf(stmp, sizeof(stmp), "$%04X", (int)FCEUPPU_PeekAddress()); ppuAddrDsp->setText( tr(stmp) ); - sprintf(stmp, "$%02X", PPU[3] ); + snprintf(stmp, sizeof(stmp), "$%02X", PPU[3] ); oamAddrDsp->setText( tr(stmp) ); extern int linestartts; @@ -4302,41 +4302,41 @@ void ConsoleDebugger::updateRegisterView(void) if (!vblankScanLines) { // Idle scanline (240) - sprintf(str, "%d", scanline); // was "Idle %d" + snprintf(str, sizeof(str), "%d", scanline); // was "Idle %d" } else if (scanline + vblankScanLines == (PAL?311:261)) { // Pre-render - sprintf(str, "-1"); // was "Prerender -1" + snprintf(str, sizeof(str), "-1"); // was "Prerender -1" } else { // Vblank lines (241-260/310) - sprintf(str, "%d", scanline + vblankScanLines); // was "Vblank %d" + snprintf(str, sizeof(str), "%d", scanline + vblankScanLines); // was "Vblank %d" } - sprintf(str2, "%d", vblankPixel); + snprintf(str2, sizeof(str2), "%d", vblankPixel); } else { // Scanlines 0 - 239 - sprintf(str, "%d", scanline); - sprintf(str2, "%d", ppupixel); + snprintf(str, sizeof(str), "%d", scanline); + snprintf(str2, sizeof(str2), "%d", ppupixel); } if(newppu) { - sprintf(str ,"%d",newppu_get_scanline()); - sprintf(str2,"%d",newppu_get_dot()); + snprintf(str , sizeof(str), "%d",newppu_get_scanline()); + snprintf(str2, sizeof(str2), "%d",newppu_get_dot()); } - sprintf( stmp, "%s", str ); + snprintf( stmp, sizeof(stmp), "%s", str ); ppuScanLineDsp->setText( tr(stmp) ); - sprintf( stmp, "%s", str2 ); + snprintf( stmp, sizeof(stmp), "%s", str2 ); ppuPixelDsp->setText( tr(stmp) ); int ppuScrollPosX, ppuScrollPosY; ppu_getScroll( ppuScrollPosX, ppuScrollPosY); - sprintf( stmp, "%i", ppuScrollPosX ); + snprintf( stmp, sizeof(stmp), "%i", ppuScrollPosX ); ppuScrollX->setText( tr(stmp) ); - sprintf( stmp, "%i", ppuScrollPosY ); + snprintf( stmp, sizeof(stmp), "%i", ppuScrollPosY ); ppuScrollY->setText( tr(stmp) ); } //---------------------------------------------------------------------------- @@ -4415,7 +4415,7 @@ void ConsoleDebugger::updatePeriodic(void) if ( lastBpIdx >= 0 ) { char stmp[128]; - sprintf( stmp, " Emulator Stopped / Paused at Breakpoint: %i", lastBpIdx ); + snprintf( stmp, sizeof(stmp), " Emulator Stopped / Paused at Breakpoint: %i", lastBpIdx ); emuStatLbl->setText( tr(stmp) ); } else @@ -5374,7 +5374,7 @@ void QAsmView::setSelAddrToLine( int line ) selAddrWidth = 4; selAddrValue = addr; selAddrType = 0; - sprintf( selAddrText, "%04X", addr ); + snprintf( selAddrText, sizeof(selAddrText), "%04X", addr ); if ( parent ) @@ -5598,7 +5598,7 @@ bool QAsmView::event(QEvent *event) } else if ( showSymHexDecode ) { - sprintf( stmp, "$%04X", asmEntry[line]->sym.offset() ); + snprintf( stmp, sizeof(stmp), "$%04X", asmEntry[line]->sym.offset() ); QToolTip::showText(helpEvent->globalPos(), tr(stmp), this ); } @@ -5606,11 +5606,11 @@ bool QAsmView::event(QEvent *event) { if ( asmEntry[line]->bank < 0 ) { - sprintf( stmp, "ADDR:\t$%04X", asmEntry[line]->addr ); + snprintf( stmp, sizeof(stmp), "ADDR:\t$%04X", asmEntry[line]->addr ); } else { - sprintf( stmp, "ADDR:\t$%04X\nBANK:\t$%02X\nROM:\t$%06X", + snprintf( stmp, sizeof(stmp), "ADDR:\t$%04X\nBANK:\t$%02X\nROM:\t$%06X", asmEntry[line]->addr, asmEntry[line]->bank, asmEntry[line]->rom ); } @@ -5631,11 +5631,11 @@ bool QAsmView::event(QEvent *event) if ( bank < 0 ) { - sprintf( stmp, "ADDR:\t$%04X", addr ); + snprintf( stmp, sizeof(stmp), "ADDR:\t$%04X", addr ); } else { - sprintf( stmp, "ADDR:\t$%04X\nBANK:\t$%02X\nROM:\t$%06X", + snprintf( stmp, sizeof(stmp), "ADDR:\t$%04X\nBANK:\t$%02X\nROM:\t$%06X", addr, bank, romOfs ); } @@ -5909,7 +5909,7 @@ void QAsmView::mouseMoveEvent(QMouseEvent * event) bank = getBank(addr); romOfs = GetNesFileAddress(addr); - sprintf( txt, "CPU Address: %02X:%04X", bank, addr); + snprintf( txt, sizeof(txt), "CPU Address: %02X:%04X", bank, addr); s.assign( txt ); @@ -5923,14 +5923,14 @@ void QAsmView::mouseMoveEvent(QMouseEvent * event) { fileName = "..."; } - sprintf( txt, "\nOffset 0x%06X in File \"%s\" (NL file: %X)", romOfs, fileName, bank); + snprintf( txt, sizeof(txt), "\nOffset 0x%06X in File \"%s\" (NL file: %X)", romOfs, fileName, bank); s.append( txt ); } } else { - sprintf( txt, "CPU Address: %04X", addr); + snprintf( txt, sizeof(txt), "CPU Address: %04X", addr); s.assign( txt ); } @@ -6212,13 +6212,13 @@ void QAsmView::mousePressEvent(QMouseEvent * event) if ( selAddrType ) { - sprintf( selAddrText, "%06X", addr ); + snprintf( selAddrText, sizeof(selAddrText), "%06X", addr ); selAddrWidth = 6; selAddrChar = pcLocLinePos+1; } else { - sprintf( selAddrText, "%04X", addr ); + snprintf( selAddrText, sizeof(selAddrText), "%04X", addr ); selAddrWidth = 4; selAddrChar = pcLocLinePos+3; } @@ -6357,7 +6357,7 @@ void QAsmView::contextMenuEvent(QContextMenuEvent *event) if ( ctxMenuAddrType == 0 ) { - sprintf( stmp, "Go to $%04X\tDouble+Click", ctxMenuAddr ); + snprintf( stmp, sizeof(stmp), "Go to $%04X\tDouble+Click", ctxMenuAddr ); act = new QAction(tr(stmp), &menu); menu.addAction(act); //act->setShortcut( QKeySequence(tr("Ctrl+F10"))); @@ -7105,7 +7105,7 @@ void DebuggerStackDisplay::contextMenuEvent(QContextMenuEvent *event) { char stmp[8]; - sprintf( stmp, "%i", i+1 ); + snprintf( stmp, sizeof(stmp), "%i", i+1 ); bytesPerLineAct[i] = new QAction(tr(stmp), &menu); bytesPerLineAct[i]->setCheckable(true); @@ -7172,11 +7172,11 @@ void DebuggerStackDisplay::updateText(void) { if ( showAddrs || (stackBytesPerLine <= 1) ) { - sprintf( stmp, "%03X: %02X", stackPtr, GetMem(stackPtr) ); + snprintf( stmp, sizeof(stmp), "%03X: %02X", stackPtr, GetMem(stackPtr) ); } else { - sprintf( stmp, "%02X", GetMem(stackPtr) ); + snprintf( stmp, sizeof(stmp), "%02X", GetMem(stackPtr) ); } stackLine.assign( stmp ); @@ -7194,21 +7194,21 @@ void DebuggerStackDisplay::updateText(void) { if ( showAddrs ) { - sprintf( stmp, "\n%03X: %02X", stackPtr, GetMem(stackPtr) ); + snprintf( stmp, sizeof(stmp), "\n%03X: %02X", stackPtr, GetMem(stackPtr) ); } else { - sprintf( stmp, "\n%02X", GetMem(stackPtr) ); + snprintf( stmp, sizeof(stmp), "\n%02X", GetMem(stackPtr) ); } } else { - sprintf( stmp, ",%02X", GetMem(stackPtr) ); + snprintf( stmp, sizeof(stmp), ",%02X", GetMem(stackPtr) ); } } else { - sprintf( stmp, "\n%03X: %02X", stackPtr, GetMem(stackPtr) ); + snprintf( stmp, sizeof(stmp), "\n%03X: %02X", stackPtr, GetMem(stackPtr) ); } stackLine.append( stmp ); @@ -7312,11 +7312,11 @@ asmLookAheadPopup::asmLookAheadPopup( int addr, QWidget *parent ) hbox = new QHBoxLayout(); vbox->addLayout( hbox ); - sprintf( stmp, "%02X : $%04X", bank, addr ); + snprintf( stmp, sizeof(stmp), "%02X : $%04X", bank, addr ); cpuAddr->setText( tr(stmp) ); - sprintf( stmp, "#$%02X", GetMem(addr) ); + snprintf( stmp, sizeof(stmp), "#$%02X", GetMem(addr) ); cpuVal->setText( tr(stmp) ); - sprintf( stmp, "$%06X", romOfs ); + snprintf( stmp, sizeof(stmp), "$%06X", romOfs ); romAddr->setText( tr(stmp) ); lbl = new QLabel( tr("CPU ADDR:") ); @@ -7343,9 +7343,9 @@ asmLookAheadPopup::asmLookAheadPopup( int addr, QWidget *parent ) hbox = new QHBoxLayout(); vbox->addLayout( hbox ); - sprintf( stmp, "$%04X", addr ); + snprintf( stmp, sizeof(stmp), "$%04X", addr ); cpuAddr->setText( tr(stmp) ); - sprintf( stmp, "#$%02X", GetMem(addr) ); + snprintf( stmp, sizeof(stmp), "#$%02X", GetMem(addr) ); cpuVal->setText( tr(stmp) ); lbl = new QLabel( tr("CPU ADDR:") ); @@ -7502,10 +7502,10 @@ ppuRegPopup::ppuRegPopup( QWidget *parent ) sprite0hit_cbox = new QCheckBox( tr("Sprite 0 Hit") ); spriteOvrflw_cbox = new QCheckBox( tr("Sprite Overflow") ); - sprintf( stmp, "$%04X", 0x2000 + (0x400*(PPU[0] & 0x03))); + snprintf( stmp, sizeof(stmp), "$%04X", 0x2000 + (0x400*(PPU[0] & 0x03))); ppuBgAddr->setText( tr(stmp) ); - sprintf( stmp, "$%04X", (PPU[0] & 0x08) ? 0x1000 : 0x0000 ); + snprintf( stmp, sizeof(stmp), "$%04X", (PPU[0] & 0x08) ? 0x1000 : 0x0000 ); ppuSprAddr->setText( tr(stmp) ); nmiBlank_cbox->setChecked( PPU[0] & 0x80 ); @@ -7865,7 +7865,7 @@ DebugBreakOnDialog::DebugBreakOnDialog(int type, QWidget *parent ) refMode = breakOnInstrMode; threshold = break_instructions_limit; - sprintf(stmp, "Current Instruction Count: %10llu (+%llu)", totalCount, deltaCount); + snprintf(stmp, sizeof(stmp), "Current Instruction Count: %10llu (+%llu)", totalCount, deltaCount); currLbl->setText( tr(stmp) ); } @@ -7889,7 +7889,7 @@ DebugBreakOnDialog::DebugBreakOnDialog(int type, QWidget *parent ) refMode = breakOnCycleMode; threshold = break_cycles_limit; - sprintf(stmp, "Current Cycle Count: %10llu (+%llu)", totalCount, deltaCount); + snprintf(stmp, sizeof(stmp), "Current Cycle Count: %10llu (+%llu)", totalCount, deltaCount); currLbl->setText( tr(stmp) ); } @@ -7969,7 +7969,7 @@ DebugBreakOnDialog::DebugBreakOnDialog(int type, QWidget *parent ) grid->addWidget( btn, row, 4-(col*2) ); - sprintf( stmp, "%+i%c", -bb, c); + snprintf( stmp, sizeof(stmp), "%+i%c", -bb, c); btn->setText( tr(stmp) ); @@ -7979,7 +7979,7 @@ DebugBreakOnDialog::DebugBreakOnDialog(int type, QWidget *parent ) grid->addWidget( btn, row, 4-(col*2)+1 ); - sprintf( stmp, "%+i%c", bb, c); + snprintf( stmp, sizeof(stmp), "%+i%c", bb, c); btn->setText( tr(stmp) ); @@ -8118,7 +8118,7 @@ void DebugBreakOnDialog::updateCurrent(void) totalCount = total_instructions; deltaCount = delta_instructions; - sprintf(stmp, "Current Instruction Count: %10llu (+%llu)", totalCount, deltaCount); + snprintf(stmp, sizeof(stmp), "Current Instruction Count: %10llu (+%llu)", totalCount, deltaCount); currLbl->setText( tr(stmp) ); } @@ -8137,7 +8137,7 @@ void DebugBreakOnDialog::updateCurrent(void) ResetDebugStatisticsCounters(); deltaCount = 0; } - sprintf(stmp, "Current Cycle Count: %10llu (+%llu)", totalCount, deltaCount); + snprintf(stmp, sizeof(stmp), "Current Cycle Count: %10llu (+%llu)", totalCount, deltaCount); currLbl->setText( tr(stmp) ); } @@ -8195,7 +8195,7 @@ void DebugBreakOnDialog::setThreshold( unsigned long long int val ) threshold = val; - sprintf( stmp, "%llu", threshold ); + snprintf( stmp, sizeof(stmp), "%llu", threshold ); countEntryBox->setText( tr(stmp) ); @@ -8229,11 +8229,11 @@ void DebugBreakOnDialog::updateLabel(void) if ( delta > 0 ) { - sprintf( stmp, "Will break in %lli CPU Instruction%s", delta, (delta > 1) ? "s":"" ); + snprintf( stmp, sizeof(stmp), "Will break in %lli CPU Instruction%s", delta, (delta > 1) ? "s":"" ); } else { - sprintf( stmp, "Will break immediately, CPU instruction count already exceeds value by %lli.", -delta); + snprintf( stmp, sizeof(stmp), "Will break immediately, CPU instruction count already exceeds value by %lli.", -delta); } } else @@ -8242,11 +8242,11 @@ void DebugBreakOnDialog::updateLabel(void) if ( delta > 0 ) { - sprintf( stmp, "Will break in %lli CPU Instruction%s", delta, (delta > 1) ? "s":"" ); + snprintf( stmp, sizeof(stmp), "Will break in %lli CPU Instruction%s", delta, (delta > 1) ? "s":"" ); } else { - sprintf( stmp, "Will break immediately, CPU instruction count already exceeds value by %lli.", -delta); + snprintf( stmp, sizeof(stmp), "Will break immediately, CPU instruction count already exceeds value by %lli.", -delta); } } } @@ -8258,11 +8258,11 @@ void DebugBreakOnDialog::updateLabel(void) if ( delta > 0 ) { - sprintf( stmp, "Will break in %lli CPU cycle%s", delta, (delta > 1) ? "s":"" ); + snprintf( stmp, sizeof(stmp), "Will break in %lli CPU cycle%s", delta, (delta > 1) ? "s":"" ); } else { - sprintf( stmp, "Will break immediately, CPU cycle count already exceeds value by %lli.", -delta); + snprintf( stmp, sizeof(stmp), "Will break immediately, CPU cycle count already exceeds value by %lli.", -delta); } } else @@ -8271,11 +8271,11 @@ void DebugBreakOnDialog::updateLabel(void) if ( delta > 0 ) { - sprintf( stmp, "Will break in %lli CPU cycle%s", delta, (delta > 1) ? "s":"" ); + snprintf( stmp, sizeof(stmp), "Will break in %lli CPU cycle%s", delta, (delta > 1) ? "s":"" ); } else { - sprintf( stmp, "Will break immediately, CPU cycle count already exceeds value %lli.", -delta); + snprintf( stmp, sizeof(stmp), "Will break immediately, CPU cycle count already exceeds value %lli.", -delta); } } } diff --git a/src/drivers/Qt/ConsoleSoundConf.cpp b/src/drivers/Qt/ConsoleSoundConf.cpp index 8170e2f3..4bc783d4 100644 --- a/src/drivers/Qt/ConsoleSoundConf.cpp +++ b/src/drivers/Qt/ConsoleSoundConf.cpp @@ -332,7 +332,7 @@ void ConsoleSndConfDialog_t::periodicUpdate(void) bufUsage->setValue( (int)(percBufUse) ); - sprintf( stmp, "Sink Starve Count: %u", nes_shm->sndBuf.starveCounter ); + snprintf( stmp, sizeof(stmp), "Sink Starve Count: %u", nes_shm->sndBuf.starveCounter ); starveLbl->setText( tr(stmp) ); @@ -396,7 +396,7 @@ void ConsoleSndConfDialog_t::setSliderFromProperty(QSlider *slider, QLabel *lbl, char stmp[32]; g_config->getOption(property, &pval); slider->setValue(pval); - sprintf(stmp, "%i", pval); + snprintf(stmp, sizeof(stmp), "%i", pval); lbl->setText(stmp); } //---------------------------------------------------- @@ -404,7 +404,7 @@ void ConsoleSndConfDialog_t::bufSizeChanged(int value) { char stmp[32]; - sprintf(stmp, "%i", value); + snprintf(stmp, sizeof(stmp), "%i", value); bufSizeLabel->setText(stmp); @@ -422,7 +422,7 @@ void ConsoleSndConfDialog_t::volumeChanged(int value) { char stmp[32]; - sprintf(stmp, "%i", value); + snprintf(stmp, sizeof(stmp), "%i", value); volLbl->setText(stmp); @@ -439,7 +439,7 @@ void ConsoleSndConfDialog_t::triangleChanged(int value) { char stmp[32]; - sprintf(stmp, "%i", value); + snprintf(stmp, sizeof(stmp), "%i", value); triLbl->setText(stmp); @@ -456,7 +456,7 @@ void ConsoleSndConfDialog_t::square1Changed(int value) { char stmp[32]; - sprintf(stmp, "%i", value); + snprintf(stmp, sizeof(stmp), "%i", value); sqr1Lbl->setText(stmp); @@ -473,7 +473,7 @@ void ConsoleSndConfDialog_t::square2Changed(int value) { char stmp[32]; - sprintf(stmp, "%i", value); + snprintf(stmp, sizeof(stmp), "%i", value); sqr2Lbl->setText(stmp); @@ -490,7 +490,7 @@ void ConsoleSndConfDialog_t::noiseChanged(int value) { char stmp[32]; - sprintf(stmp, "%i", value); + snprintf(stmp, sizeof(stmp), "%i", value); nseLbl->setText(stmp); @@ -507,7 +507,7 @@ void ConsoleSndConfDialog_t::pcmChanged(int value) { char stmp[32]; - sprintf(stmp, "%i", value); + snprintf(stmp, sizeof(stmp), "%i", value); pcmLbl->setText(stmp); diff --git a/src/drivers/Qt/ConsoleUtilities.cpp b/src/drivers/Qt/ConsoleUtilities.cpp index 2988c3dd..3e4d6862 100644 --- a/src/drivers/Qt/ConsoleUtilities.cpp +++ b/src/drivers/Qt/ConsoleUtilities.cpp @@ -1339,7 +1339,7 @@ QString fceuGetOpcodeToolTip( uint8_t *opcode, int size ) for (int i=0; isetFont( font ); scrRateReadout->setReadOnly(true); scrRateReadout->setAlignment(Qt::AlignCenter); - sprintf( stmp, "%.3f", consoleWindow->getRefreshRate() ); + snprintf( stmp, sizeof(stmp), "%.3f", consoleWindow->getRefreshRate() ); scrRateReadout->setText( tr(stmp) ); hbox->addWidget( new QLabel( tr("Refresh Rate (Hz):") ) ); @@ -606,11 +606,11 @@ void ConsoleVideoConfDialog_t::updateReadouts(void) v = consoleWindow->viewport_Interface->size(); } - sprintf( stmp, "%i x %i ", w.width(), w.height() ); + snprintf( stmp, sizeof(stmp), "%i x %i ", w.width(), w.height() ); winSizeReadout->setText( tr(stmp) ); - sprintf( stmp, "%i x %i ", v.width(), v.height() ); + snprintf( stmp, sizeof(stmp), "%i x %i ", v.width(), v.height() ); vpSizeReadout->setText( tr(stmp) ); } diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 84c337d6..d6f0dafc 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -1038,7 +1038,7 @@ void consoleWin_t::createMainMenu(void) { char stmp[8]; - sprintf( stmp, "Slot &%i", i ); + snprintf( stmp, sizeof(stmp), "Slot &%i", i ); state[i] = new QAction(tr(stmp), this); state[i]->setCheckable(true); @@ -1254,7 +1254,7 @@ void consoleWin_t::createMainMenu(void) { char stmp[8]; - sprintf( stmp, "&%ix", i+1 ); + snprintf( stmp, sizeof(stmp), "&%ix", i+1 ); winSizeAct[i] = new QAction(tr(stmp), this); @@ -1629,7 +1629,7 @@ void consoleWin_t::createMainMenu(void) for (int j=1; j<=(6-i); j++) { - sprintf( stmp, "%i On, %i Off", i, j ); + snprintf( stmp, sizeof(stmp), "%i On, %i Off", i, j ); autoFireMenuAction *afAct = new autoFireMenuAction( i, j, tr(stmp), this); afAct->setCheckable(true); group->addAction(afAct); @@ -2217,7 +2217,7 @@ void consoleWin_t::buildRecentRomMenu(void) for (int i=0; i<10; i++) { - sprintf(buf, "SDL.RecentRom%02i", i); + snprintf(buf, sizeof(buf), "SDL.RecentRom%02i", i); g_config->getOption( buf, &s); @@ -2270,7 +2270,7 @@ void consoleWin_t::saveRecentRomMenu(void) for (it=romList.begin(); it != romList.end(); it++) { s = *it; - sprintf(buf, "SDL.RecentRom%02i", i); + snprintf(buf, sizeof(buf), "SDL.RecentRom%02i", i); g_config->setOption( buf, *s ); @@ -2279,7 +2279,7 @@ void consoleWin_t::saveRecentRomMenu(void) } for (i = romList.size(); i < 10; i++) { - sprintf(buf, "SDL.RecentRom%02i", i); + snprintf(buf, sizeof(buf), "SDL.RecentRom%02i", i); g_config->setOption( buf, ""); } @@ -2290,7 +2290,7 @@ void consoleWin_t::clearRecentRomMenu() char buf[128]; for (int i = 0; i < 10; i++) { - sprintf(buf, "SDL.RecentRom%02i", i); + snprintf(buf, sizeof(buf), "SDL.RecentRom%02i", i); g_config->setOption( buf, ""); } clearRomList(); @@ -3476,7 +3476,7 @@ void consoleWin_t::warnAmbiguousShortcut( QShortcut *shortcut) std::string msg; int c = 0; - sprintf( stmp, "Error: Ambiguous Shortcut Activation for Key Sequence: '%s'\n", shortcut->key().toString().toLocal8Bit().constData() ); + snprintf( stmp, sizeof(stmp), "Error: Ambiguous Shortcut Activation for Key Sequence: '%s'\n", shortcut->key().toString().toLocal8Bit().constData() ); msg.assign( stmp ); diff --git a/src/drivers/Qt/FamilyKeyboard.cpp b/src/drivers/Qt/FamilyKeyboard.cpp index fd82bd4e..e905229b 100644 --- a/src/drivers/Qt/FamilyKeyboard.cpp +++ b/src/drivers/Qt/FamilyKeyboard.cpp @@ -616,11 +616,11 @@ FKBConfigDialog::FKBConfigDialog(QWidget *parent) if ( strcmp( keyNames[j], keyNames[j+1] ) == 0 ) { - sprintf( stmp, " %s ", keyNames[j] ); + snprintf( stmp, sizeof(stmp), " %s ", keyNames[j] ); } else { - sprintf( stmp, " %s - %s ", keyNames[j], keyNames[j+1] ); + snprintf( stmp, sizeof(stmp), " %s - %s ", keyNames[j], keyNames[j+1] ); } item->setText(0, tr(stmp) ); @@ -1331,26 +1331,26 @@ void FKBConfigDialog::mappingSave(void) } stmp[k] = 0; - //sprintf(stmp, "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum)); + //snprintf(stmp, sizeof(stmp), "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum)); } else { if (fkbmap[i].ButtonNum & 0x2000) { /* Hat "button" */ - sprintf(stmp, "h%i.%i", + snprintf(stmp, sizeof(stmp), "h%i.%i", (fkbmap[i].ButtonNum >> 8) & 0x1F, fkbmap[i].ButtonNum & 0xFF); } else if (fkbmap[i].ButtonNum & 0x8000) { /* Axis "button" */ - sprintf(stmp, "%ca%i", + snprintf(stmp, sizeof(stmp), "%ca%i", (fkbmap[i].ButtonNum & 0x4000) ? '-' : '+', fkbmap[i].ButtonNum & 0x3FFF); } else { /* Button */ - sprintf(stmp, "b%i", fkbmap[i].ButtonNum); + snprintf(stmp, sizeof(stmp), "b%i", fkbmap[i].ButtonNum); } } fprintf( fp, "%s=%s\n", FamilyKeyBoardNames[i], stmp ); @@ -1462,7 +1462,7 @@ FKBKeyMapDialog::FKBKeyMapDialog( int idx, QWidget *parent ) setLayout( mainLayout ); - sprintf( stmp, "Press a key to set new physical mapping for the '%s' Key", keyNames[idx*2] ); + snprintf( stmp, sizeof(stmp), "Press a key to set new physical mapping for the '%s' Key", keyNames[idx*2] ); msgLbl = new QLabel( tr(stmp) ); diff --git a/src/drivers/Qt/FrameTimingStats.cpp b/src/drivers/Qt/FrameTimingStats.cpp index e2551da8..babce0ae 100644 --- a/src/drivers/Qt/FrameTimingStats.cpp +++ b/src/drivers/Qt/FrameTimingStats.cpp @@ -209,111 +209,111 @@ void FrameTimingDialog_t::updateTimingStats(void) getFrameTimingStats(&stats); // Absolute - sprintf(stmp, "%.3f", stats.frameTimeAbs.tgt * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeAbs.tgt * 1e3); frameTimeAbs->setText(1, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeAbs.cur * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeAbs.cur * 1e3); frameTimeAbs->setText(2, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeAbs.min * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeAbs.min * 1e3); frameTimeAbs->setText(3, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeAbs.max * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeAbs.max * 1e3); frameTimeAbs->setText(4, tr(stmp)); // Delta - sprintf(stmp, "%.3f", stats.frameTimeDel.tgt * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeDel.tgt * 1e3); frameTimeDel->setText(1, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeDel.cur * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeDel.cur * 1e3); frameTimeDel->setText(2, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeDel.min * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeDel.min * 1e3); frameTimeDel->setText(3, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeDel.max * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeDel.max * 1e3); frameTimeDel->setText(4, tr(stmp)); // Work - sprintf(stmp, "lt %.3f", stats.frameTimeWork.tgt * 1e3); + snprintf(stmp, sizeof(stmp), "lt %.3f", stats.frameTimeWork.tgt * 1e3); frameTimeWork->setText(1, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeWork.cur * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeWork.cur * 1e3); frameTimeWork->setText(2, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeWork.min * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeWork.min * 1e3); frameTimeWork->setText(3, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeWork.max * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeWork.max * 1e3); frameTimeWork->setText(4, tr(stmp)); // Idle - sprintf(stmp, "gt %.3f", stats.frameTimeIdle.tgt * 1e3); + snprintf(stmp, sizeof(stmp), "gt %.3f", stats.frameTimeIdle.tgt * 1e3); frameTimeIdle->setText(1, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeIdle.cur * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeIdle.cur * 1e3); frameTimeIdle->setText(2, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeIdle.min * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeIdle.min * 1e3); frameTimeIdle->setText(3, tr(stmp)); - sprintf(stmp, "%.3f", stats.frameTimeIdle.max * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.frameTimeIdle.max * 1e3); frameTimeIdle->setText(4, tr(stmp)); // Work % - sprintf(stmp, "lt %.1f", 100.0 * stats.frameTimeWork.tgt / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "lt %.1f", 100.0 * stats.frameTimeWork.tgt / stats.frameTimeAbs.tgt); frameTimeWorkPct->setText(1, tr(stmp)); - sprintf(stmp, "%.1f", 100.0 * stats.frameTimeWork.cur / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "%.1f", 100.0 * stats.frameTimeWork.cur / stats.frameTimeAbs.tgt); frameTimeWorkPct->setText(2, tr(stmp)); - sprintf(stmp, "%.1f", 100.0 * stats.frameTimeWork.min / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "%.1f", 100.0 * stats.frameTimeWork.min / stats.frameTimeAbs.tgt); frameTimeWorkPct->setText(3, tr(stmp)); - sprintf(stmp, "%.1f", 100.0 * stats.frameTimeWork.max / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "%.1f", 100.0 * stats.frameTimeWork.max / stats.frameTimeAbs.tgt); frameTimeWorkPct->setText(4, tr(stmp)); // Idle % - sprintf(stmp, "gt %.1f", 100.0 * stats.frameTimeIdle.tgt / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "gt %.1f", 100.0 * stats.frameTimeIdle.tgt / stats.frameTimeAbs.tgt); frameTimeIdlePct->setText(1, tr(stmp)); - sprintf(stmp, "%.1f", 100.0 * stats.frameTimeIdle.cur / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "%.1f", 100.0 * stats.frameTimeIdle.cur / stats.frameTimeAbs.tgt); frameTimeIdlePct->setText(2, tr(stmp)); - sprintf(stmp, "%.1f", 100.0 * stats.frameTimeIdle.min / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "%.1f", 100.0 * stats.frameTimeIdle.min / stats.frameTimeAbs.tgt); frameTimeIdlePct->setText(3, tr(stmp)); - sprintf(stmp, "%.1f", 100.0 * stats.frameTimeIdle.max / stats.frameTimeAbs.tgt); + snprintf(stmp, sizeof(stmp), "%.1f", 100.0 * stats.frameTimeIdle.max / stats.frameTimeAbs.tgt); frameTimeIdlePct->setText(4, tr(stmp)); // Video - sprintf(stmp, "%.3f", stats.videoTimeDel.tgt * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.videoTimeDel.tgt * 1e3); videoTimeAbs->setText(1, tr(stmp)); - sprintf(stmp, "%.3f", stats.videoTimeDel.cur * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.videoTimeDel.cur * 1e3); videoTimeAbs->setText(2, tr(stmp)); - sprintf(stmp, "%.3f", stats.videoTimeDel.min * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.videoTimeDel.min * 1e3); videoTimeAbs->setText(3, tr(stmp)); - sprintf(stmp, "%.3f", stats.videoTimeDel.max * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.videoTimeDel.max * 1e3); videoTimeAbs->setText(4, tr(stmp)); // Emulator to GUI Thread Signal Delay - sprintf(stmp, "%.3f", stats.emuSignalDelay.tgt * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.emuSignalDelay.tgt * 1e3); emuSignalDelay->setText(1, tr(stmp)); - sprintf(stmp, "%.3f", stats.emuSignalDelay.cur * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.emuSignalDelay.cur * 1e3); emuSignalDelay->setText(2, tr(stmp)); - sprintf(stmp, "%.3f", stats.emuSignalDelay.min * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.emuSignalDelay.min * 1e3); emuSignalDelay->setText(3, tr(stmp)); - sprintf(stmp, "%.3f", stats.emuSignalDelay.max * 1e3); + snprintf(stmp, sizeof(stmp), "%.3f", stats.emuSignalDelay.max * 1e3); emuSignalDelay->setText(4, tr(stmp)); // Late Count - sprintf(stmp, "%u", stats.lateCount); + snprintf(stmp, sizeof(stmp), "%u", stats.lateCount); frameLateCount->setText(1, tr("0")); frameLateCount->setText(2, tr(stmp)); diff --git a/src/drivers/Qt/GameGenie.cpp b/src/drivers/Qt/GameGenie.cpp index 1789120c..e2131499 100644 --- a/src/drivers/Qt/GameGenie.cpp +++ b/src/drivers/Qt/GameGenie.cpp @@ -368,7 +368,7 @@ void GameGenieDialog_t::ggChanged(const QString &s) if ( a >= 0 ) { - sprintf( stmp, "%04X", a ); + snprintf( stmp, sizeof(stmp), "%04X", a ); addr->setText( tr(stmp) ); } @@ -379,7 +379,7 @@ void GameGenieDialog_t::ggChanged(const QString &s) if ( v >= 0 ) { - sprintf( stmp, "%02X", v ); + snprintf( stmp, sizeof(stmp), "%02X", v ); val->setText( tr(stmp) ); } @@ -390,7 +390,7 @@ void GameGenieDialog_t::ggChanged(const QString &s) if ( c >= 0 ) { - sprintf( stmp, "%02X", c ); + snprintf( stmp, sizeof(stmp), "%02X", c ); cmp->setText( tr(stmp) ); } @@ -467,7 +467,7 @@ void GameGenieDialog_t::ListGGAddresses(void) { item = new QTreeWidgetItem(); - sprintf(str, "%06X", i + (a & 0x1FFF) + 0x10); + snprintf(str, sizeof(str), "%06X", i + (a & 0x1FFF) + 0x10); //printf("Added ROM ADDR: %s\n", str ); item->setText( 0, tr(str) ); diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index f3b00caf..aa344788 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -215,7 +215,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) { if (js->isConnected()) { - sprintf(stmp, "%i: %s", i, js->getName()); + snprintf(stmp, sizeof(stmp), "%i: %s", i, js->getName()); devSel->addItem(tr(stmp), i); } } @@ -328,7 +328,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) char text[64]; QLabel *buttonName; - sprintf(text, "%s:", GamePadNames[i]); + snprintf(text, sizeof(text), "%s:", GamePadNames[i]); //hbox2 = new QHBoxLayout(); @@ -506,7 +506,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) for (int i = 0; i < GAMEPAD_NUM_DEVICES; i++) { - sprintf(stmp, "SDL.Input.GamePad.%i.", i); + snprintf(stmp, sizeof(stmp), "SDL.Input.GamePad.%i.", i); prefix = stmp; g_config->getOption(prefix + "Profile", &lcl[i].profile); @@ -595,7 +595,7 @@ void GamePadConfDialog_t::loadMapList(void) fileList = dir.entryList(filters, QDir::Files, QDir::NoSort); - sprintf(stmp, "SDL.Input.GamePad.%u.", portNum); + snprintf(stmp, sizeof(stmp), "SDL.Input.GamePad.%u.", portNum); prefix = stmp; g_config->getOption(prefix + "Profile", &mapName); @@ -880,7 +880,7 @@ void GamePadConfDialog_t::changeButton(int padNo, int x) ( strcmp( js1->getGUID(), js2->getGUID() ) != 0 ) ) { char stmp[256]; - sprintf( stmp, "Joystick device GUID MisMatch\n\nSelected device is: \n\t%s\n\nbut button mapping is from: \n\t%s", + snprintf( stmp, sizeof(stmp), "Joystick device GUID MisMatch\n\nSelected device is: \n\t%s\n\nbut button mapping is from: \n\t%s", js1->getName(), js2->getName() ); QMessageBox::warning( this, tr("Mapping Error"), tr(stmp), QMessageBox::Cancel, QMessageBox::Cancel ); @@ -1100,7 +1100,7 @@ void GamePadConfDialog_t::saveConfig(void) const char *guid; std::string prefix, mapName; - sprintf(stmp, "SDL.Input.GamePad.%u.", portNum); + snprintf(stmp, sizeof(stmp), "SDL.Input.GamePad.%u.", portNum); prefix = stmp; mapName = mapSel->currentText().toLocal8Bit().constData(); @@ -1134,7 +1134,7 @@ void GamePadConfDialog_t::createNewProfile(const char *name) mapSel->setCurrentIndex(mapSel->count() - 1); saveConfig(); - sprintf(stmp, "Mapping Created: %s/%s \n", GamePad[portNum].getGUID(), name); + snprintf(stmp, sizeof(stmp), "Mapping Created: %s/%s \n", GamePad[portNum].getGUID(), name); mapMsg->setText(tr(stmp)); } //---------------------------------------------------- @@ -1180,11 +1180,11 @@ void GamePadConfDialog_t::loadProfileCallback(void) { saveConfig(); - sprintf(stmp, "Mapping Loaded: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); + snprintf(stmp, sizeof(stmp), "Mapping Loaded: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); } else { - sprintf(stmp, "Error: Failed to Load Mapping: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); + snprintf(stmp, sizeof(stmp), "Error: Failed to Load Mapping: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); } mapMsg->setText(tr(stmp)); @@ -1207,11 +1207,11 @@ void GamePadConfDialog_t::saveProfileCallback(void) { saveConfig(); - sprintf(stmp, "Mapping Saved: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); + snprintf(stmp, sizeof(stmp), "Mapping Saved: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); } else { - sprintf(stmp, "Error: Failed to Save Mapping: %s \n", mapName.c_str()); + snprintf(stmp, sizeof(stmp), "Error: Failed to Save Mapping: %s \n", mapName.c_str()); } mapMsg->setText(tr(stmp)); } @@ -1228,11 +1228,11 @@ void GamePadConfDialog_t::deleteProfileCallback(void) if (ret == 0) { - sprintf(stmp, "Mapping Deleted: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); + snprintf(stmp, sizeof(stmp), "Mapping Deleted: %s/%s \n", GamePad[portNum].getGUID(), mapName.c_str()); } else { - sprintf(stmp, "Error: Failed to Delete Mapping: %s \n", mapName.c_str()); + snprintf(stmp, sizeof(stmp), "Error: Failed to Delete Mapping: %s \n", mapName.c_str()); } mapMsg->setText(tr(stmp)); @@ -1269,7 +1269,7 @@ int GamePadConfDialog_t::promptToSave(void) { return 0; } - sprintf(stmp, "Warning: Gamepad mappings have not been saved for port%c ", (n > 1) ? 's' : ' '); + snprintf(stmp, sizeof(stmp), "Warning: Gamepad mappings have not been saved for port%c ", (n > 1) ? 's' : ' '); msg.assign(stmp); @@ -1278,7 +1278,7 @@ int GamePadConfDialog_t::promptToSave(void) { if (padNeedsSave[i]) { - sprintf(stmp, "%i", i + 1); + snprintf(stmp, sizeof(stmp), "%i", i + 1); msg.append(stmp); @@ -1427,7 +1427,7 @@ void GamePadConfDialog_t::updatePeriodic(void) { char stmp[256]; //printf("Adding Newly Connected JS\n"); - sprintf(stmp, "%i: %s", i, js->getName()); + snprintf(stmp, sizeof(stmp), "%i: %s", i, js->getName()); devSel->addItem(tr(stmp), i); } } diff --git a/src/drivers/Qt/GuiConf.cpp b/src/drivers/Qt/GuiConf.cpp index 71bd8801..1ede8191 100644 --- a/src/drivers/Qt/GuiConf.cpp +++ b/src/drivers/Qt/GuiConf.cpp @@ -1337,7 +1337,7 @@ void GuiPaletteColorSelect::setText(void) { return; } - sprintf( stmp, "%s :: %s", gTxt, rTxt ); + snprintf( stmp, sizeof(stmp), "%s :: %s", gTxt, rTxt ); lbl->setText( tr(stmp) ); @@ -1356,7 +1356,7 @@ void GuiPaletteColorSelect::updateColor(void) { txtColor.setRgb( 255, 255, 255 ); } - sprintf( stmp, "QLabel { background-color : %s; color : %s; border-color : black; }", + snprintf( stmp, sizeof(stmp), "QLabel { background-color : %s; color : %s; border-color : black; }", color.name().toLocal8Bit().constData(), txtColor.name().toLocal8Bit().constData() ); lbl->setStyleSheet( stmp ); diff --git a/src/drivers/Qt/HexEditor.cpp b/src/drivers/Qt/HexEditor.cpp index 71413ceb..4854ddb9 100644 --- a/src/drivers/Qt/HexEditor.cpp +++ b/src/drivers/Qt/HexEditor.cpp @@ -865,7 +865,7 @@ int HexEditorCharTable_t::loadFromFile( const char *filepath ) if ( hexValue > 255 ) { - sprintf( errMsg, "Error: Line %i: Hex Value 0x%X exceeds 0xFF \n", lineNum, hexValue ); + snprintf( errMsg, sizeof(errMsg), "Error: Line %i: Hex Value 0x%X exceeds 0xFF \n", lineNum, hexValue ); retVal = -1; continue; } @@ -874,7 +874,7 @@ int HexEditorCharTable_t::loadFromFile( const char *filepath ) if ( line[i] != '=' ) { - sprintf( errMsg, "Error: Line %i: Expected assignment operator '=' but got '%c' \n", lineNum, line[i] ); + snprintf( errMsg, sizeof(errMsg), "Error: Line %i: Expected assignment operator '=' but got '%c' \n", lineNum, line[i] ); retVal = -1; continue; } @@ -929,7 +929,7 @@ int HexEditorCharTable_t::loadFromFile( const char *filepath ) if ( mapValue > 255 ) { - sprintf( errMsg, "Error: Line %i: Map Value 0x%X exceeds 0xFF \n", lineNum, mapValue ); + snprintf( errMsg, sizeof(errMsg), "Error: Line %i: Map Value 0x%X exceeds 0xFF \n", lineNum, mapValue ); retVal = -1; continue; } @@ -1519,7 +1519,7 @@ void HexEditorDialog_t::setWindowTitle(void) modeString = memViewNames[ editor->getMode() ]; - sprintf( stmp, "Hex Editor - %s: 0x%04X", modeString, editor->getAddr() ); + snprintf( stmp, sizeof(stmp), "Hex Editor - %s: 0x%04X", modeString, editor->getAddr() ); QDialog::setWindowTitle( tr(stmp) ); @@ -2253,7 +2253,7 @@ void QHexEdit::openGotoAddrDialog(void) QHBoxLayout *hbox; QPushButton *okButton, *cancelButton; - sprintf( stmp, "Specify Address [ 0x0 -> 0x%X ]", mb.size()-1 ); + snprintf( stmp, sizeof(stmp), "Specify Address [ 0x0 -> 0x%X ]", mb.size()-1 ); vbox = new QVBoxLayout(); hbox = new QHBoxLayout(); @@ -2418,7 +2418,7 @@ void QHexEdit::loadHighlightToClipboard(void) for (a=startAddr; a<=endAddr; a++) { - sprintf( c, "%02X ", memAccessFunc(a) ); + snprintf( c, sizeof(c), "%02X ", memAccessFunc(a) ); s.append(c); } @@ -3145,17 +3145,17 @@ void QHexEdit::contextMenuEvent(QContextMenuEvent *event) subMenu->addAction(act); connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamUnsetAll(void)) ); - sprintf( stmp, "Add &Read Breakpoint for Address $%04X", addr ); + snprintf( stmp, sizeof(stmp), "Add &Read Breakpoint for Address $%04X", addr ); act = new QAction(tr(stmp), &menu); menu.addAction(act); connect( act, SIGNAL(triggered(void)), this, SLOT(addRamReadBP(void)) ); - sprintf( stmp, "Add &Write Breakpoint for Address $%04X", addr ); + snprintf( stmp, sizeof(stmp), "Add &Write Breakpoint for Address $%04X", addr ); act = new QAction(tr(stmp), &menu); menu.addAction(act); connect( act, SIGNAL(triggered(void)), this, SLOT(addRamWriteBP(void)) ); - sprintf( stmp, "Add &Execute Breakpoint for Address $%04X", addr ); + snprintf( stmp, sizeof(stmp), "Add &Execute Breakpoint for Address $%04X", addr ); act = new QAction(tr(stmp), &menu); menu.addAction(act); connect( act, SIGNAL(triggered(void)), this, SLOT(addRamExecuteBP(void)) ); @@ -3167,7 +3167,7 @@ void QHexEdit::contextMenuEvent(QContextMenuEvent *event) if ( romAddr >= 0 ) { jumpToRomValue = romAddr; - sprintf( stmp, "&Go Here in ROM File: (%08X)", romAddr ); + snprintf( stmp, sizeof(stmp), "&Go Here in ROM File: (%08X)", romAddr ); act = new QAction(tr(stmp), &menu); menu.addAction(act); connect( act, SIGNAL(triggered(void)), this, SLOT(jumpToROM(void)) ); @@ -3181,12 +3181,12 @@ void QHexEdit::contextMenuEvent(QContextMenuEvent *event) break; case MODE_NES_PPU: { - sprintf( stmp, "Add &Read Breakpoint for Address $%04X", addr ); + snprintf( stmp, sizeof(stmp), "Add &Read Breakpoint for Address $%04X", addr ); act = new QAction(tr(stmp), &menu); menu.addAction(act); connect( act, SIGNAL(triggered(void)), this, SLOT(addPpuReadBP(void)) ); - sprintf( stmp, "Add &Write Breakpoint for Address $%04X", addr ); + snprintf( stmp, sizeof(stmp), "Add &Write Breakpoint for Address $%04X", addr ); act = new QAction(tr(stmp), &menu); menu.addAction(act); connect( act, SIGNAL(triggered(void)), this, SLOT(addPpuWriteBP(void)) ); @@ -3236,16 +3236,16 @@ void QHexEdit::addBookMarkCB(void) { default: case MODE_NES_RAM: - sprintf( stmp, "CPU %04X", ctxAddr ); + snprintf( stmp, sizeof(stmp), "CPU %04X", ctxAddr ); break; case MODE_NES_PPU: - sprintf( stmp, "PPU %04X", ctxAddr ); + snprintf( stmp, sizeof(stmp), "PPU %04X", ctxAddr ); break; case MODE_NES_OAM: - sprintf( stmp, "OAM %04X", ctxAddr ); + snprintf( stmp, sizeof(stmp), "OAM %04X", ctxAddr ); break; case MODE_NES_ROM: - sprintf( stmp, "ROM %04X", ctxAddr ); + snprintf( stmp, sizeof(stmp), "ROM %04X", ctxAddr ); break; } @@ -3436,7 +3436,7 @@ void QHexEdit::addRamReadBP(void) if ( ctxAddr >= 0x8000 ) { - sprintf(cond, "K==#%02X", getBank(ctxAddr)); + snprintf(cond, sizeof(cond), "K==#%02X", getBank(ctxAddr)); } retval = NewBreak( name, ctxAddr, -1, type, cond, numWPs, true); @@ -3463,7 +3463,7 @@ void QHexEdit::addRamWriteBP(void) if ( ctxAddr >= 0x8000 ) { - sprintf(cond, "K==#%02X", getBank(ctxAddr)); + snprintf(cond, sizeof(cond), "K==#%02X", getBank(ctxAddr)); } retval = NewBreak( name, ctxAddr, -1, type, cond, numWPs, true); @@ -3490,7 +3490,7 @@ void QHexEdit::addRamExecuteBP(void) if ( ctxAddr >= 0x8000 ) { - sprintf(cond, "K==#%02X", getBank(ctxAddr)); + snprintf(cond, sizeof(cond), "K==#%02X", getBank(ctxAddr)); } retval = NewBreak( name, ctxAddr, -1, type, cond, numWPs, true); @@ -3920,7 +3920,7 @@ void QHexEdit::paintEvent(QPaintEvent *event) painter.setPen( fgColor ); - sprintf( txt, "%06X", addr ); + snprintf( txt, sizeof(txt), "%06X", addr ); painter.drawText( x, y, tr(txt) ); x = pxHexOffset - pxLineXScroll; diff --git a/src/drivers/Qt/InputConf.cpp b/src/drivers/Qt/InputConf.cpp index c48e2f4f..067a1288 100644 --- a/src/drivers/Qt/InputConf.cpp +++ b/src/drivers/Qt/InputConf.cpp @@ -181,7 +181,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent) color = pal.color(QPalette::WindowText); - sprintf(stmp, "border: 2px solid #%02X%02X%02X", color.red(), color.green(), color.blue()); + snprintf(stmp, sizeof(stmp), "border: 2px solid #%02X%02X%02X", color.red(), color.green(), color.blue()); //printf("%s\n", stmp); nesPortLabel[0]->setAlignment(Qt::AlignCenter); diff --git a/src/drivers/Qt/LuaControl.cpp b/src/drivers/Qt/LuaControl.cpp index 491e6700..566c470b 100644 --- a/src/drivers/Qt/LuaControl.cpp +++ b/src/drivers/Qt/LuaControl.cpp @@ -423,7 +423,7 @@ void LuaControlDialog_t::startLuaScript(void) if (0 == FCEU_LoadLuaCode(scriptPath->text().toLocal8Bit().constData(), scriptArgs->text().toLocal8Bit().constData())) { char error_msg[2048]; - sprintf( error_msg, "Error: Could not open the selected lua script: '%s'\n", scriptPath->text().toLocal8Bit().constData()); + snprintf( error_msg, sizeof(error_msg), "Error: Could not open the selected lua script: '%s'\n", scriptPath->text().toLocal8Bit().constData()); FCEUD_PrintError(error_msg); } FCEU_WRAPPER_UNLOCK(); diff --git a/src/drivers/Qt/MoviePlay.cpp b/src/drivers/Qt/MoviePlay.cpp index 71af086d..24221ffd 100644 --- a/src/drivers/Qt/MoviePlay.cpp +++ b/src/drivers/Qt/MoviePlay.cpp @@ -247,7 +247,7 @@ void MoviePlayDialog_t::updateMovieText(void) if (fp == NULL) { - sprintf(stmp, "Error: Failed to open file '%s'", path.c_str()); + snprintf(stmp, sizeof(stmp), "Error: Failed to open file '%s'", path.c_str()); showErrorMsgWindow(stmp); clearMovieText(); return; @@ -260,7 +260,7 @@ void MoviePlayDialog_t::updateMovieText(void) validator->setMinMax(0, info.num_frames); - sprintf(stmp, "%u", (unsigned)info.num_frames); + snprintf(stmp, sizeof(stmp), "%u", (unsigned)info.num_frames); movFramesLbl->setText(tr(stmp)); pauseAtFrameEntry->setText(tr(stmp)); @@ -272,11 +272,11 @@ void MoviePlayDialog_t::updateMovieText(void) int seconds = num_seconds % 60; int minutes = (num_seconds / 60) % 60; int hours = (num_seconds / 60 / 60) % 60; - sprintf(stmp, "%02d:%02d:%02d.%02d", hours, minutes, seconds, fraction); + snprintf(stmp, sizeof(stmp), "%02d:%02d:%02d.%02d", hours, minutes, seconds, fraction); movLenLbl->setText(tr(stmp)); - sprintf(stmp, "%u", (unsigned)info.rerecord_count); + snprintf(stmp, sizeof(stmp), "%u", (unsigned)info.rerecord_count); recCountLbl->setText(tr(stmp)); @@ -297,11 +297,11 @@ void MoviePlayDialog_t::updateMovieText(void) if (info.emu_version_used < 20000) { - sprintf(stmp, "FCEU %u.%02u.%02u%s", info.emu_version_used / 10000, (info.emu_version_used / 100) % 100, (info.emu_version_used) % 100, info.emu_version_used < 9813 ? " (blip)" : ""); + snprintf(stmp, sizeof(stmp), "FCEU %u.%02u.%02u%s", info.emu_version_used / 10000, (info.emu_version_used / 100) % 100, (info.emu_version_used) % 100, info.emu_version_used < 9813 ? " (blip)" : ""); } else { - sprintf(stmp, "FCEUX %u.%02u.%02u", info.emu_version_used / 10000, (info.emu_version_used / 100) % 100, (info.emu_version_used) % 100); + snprintf(stmp, sizeof(stmp), "FCEUX %u.%02u.%02u", info.emu_version_used / 10000, (info.emu_version_used / 100) % 100, (info.emu_version_used) % 100); } emuUsedLbl->setText(tr(stmp)); @@ -315,14 +315,14 @@ void MoviePlayDialog_t::updateMovieText(void) if (strcmp(stmp, md5_asciistr(info.md5_of_rom_used)) != 0) { - sprintf(stmp, "Warning: Selected movie file '%s' may not have been created using the currently loaded ROM.", path.c_str()); + snprintf(stmp, sizeof(stmp), "Warning: Selected movie file '%s' may not have been created using the currently loaded ROM.", path.c_str()); showWarningMsgWindow(stmp); } } } else { - sprintf(stmp, "Error: Selected file '%s' does not have a recognized movie format.", path.c_str()); + snprintf(stmp, sizeof(stmp), "Error: Selected file '%s' does not have a recognized movie format.", path.c_str()); showErrorMsgWindow(stmp); clearMovieText(); } @@ -485,7 +485,7 @@ void MoviePlayDialog_t::playMovie(void) if (movieLoadError) { char stmp[256]; - sprintf(stmp, "Error: Could not load movie file: %s \n", path.c_str()); + snprintf(stmp, sizeof(stmp), "Error: Could not load movie file: %s \n", path.c_str()); showErrorMsgWindow(stmp); } else diff --git a/src/drivers/Qt/MovieRecord.cpp b/src/drivers/Qt/MovieRecord.cpp index 6753449e..246f6eef 100644 --- a/src/drivers/Qt/MovieRecord.cpp +++ b/src/drivers/Qt/MovieRecord.cpp @@ -277,7 +277,7 @@ void MovieRecordDialog_t::recordMovie(void) if (loadStateFailed) { char str [1024]; - sprintf(str, "Failed to load save state \"%s\".\nRecording from current state instead...", ic_file.c_str()); + snprintf(str, sizeof(str), "Failed to load save state \"%s\".\nRecording from current state instead...", ic_file.c_str()); FCEUD_PrintError(str); } } diff --git a/src/drivers/Qt/NameTableViewer.cpp b/src/drivers/Qt/NameTableViewer.cpp index abdfaf35..d25539f0 100644 --- a/src/drivers/Qt/NameTableViewer.cpp +++ b/src/drivers/Qt/NameTableViewer.cpp @@ -284,7 +284,7 @@ ppuNameTableViewerDialog_t::ppuNameTableViewerDialog_t(QWidget *parent) { char stmp[8]; - sprintf( stmp, "&%ix", i+1 ); + snprintf( stmp, sizeof(stmp), "&%ix", i+1 ); zoomAct[i] = new QAction(tr(stmp), this); zoomAct[i]->setCheckable(true); @@ -346,7 +346,7 @@ ppuNameTableViewerDialog_t::ppuNameTableViewerDialog_t(QWidget *parent) strcpy( stmp, "Full" ); break; default: - sprintf( stmp, "1/%i", 0x01 << i ); + snprintf( stmp, sizeof(stmp), "1/%i", 0x01 << i ); break; } @@ -768,28 +768,28 @@ void ppuNameTableViewerDialog_t::setPropertyLabels( int TileID, int TileX, int T { char stmp[32]; - sprintf( stmp, "%02X", TileID); + snprintf( stmp, sizeof(stmp), "%02X", TileID); tileIdxLbl->setText( tr(stmp) ); - sprintf( stmp, "%04X", TileID << 4); + snprintf( stmp, sizeof(stmp), "%04X", TileID << 4); tileAddrLbl->setText( tr(stmp) ); - sprintf( stmp, "%0d, %0d", TileX, TileY); + snprintf( stmp, sizeof(stmp), "%0d, %0d", TileX, TileY); tileLocLbl->setText( tr(stmp) ); - sprintf(stmp,"%04X",PPUAddress); + snprintf( stmp, sizeof(stmp), "%04X",PPUAddress); ppuAddrLbl->setText( tr(stmp) ); - sprintf(stmp,"%1X",NameTable); + snprintf( stmp, sizeof(stmp), "%1X",NameTable); nameTableLbl->setText( tr(stmp) ); - sprintf(stmp,"%02X",Attrib); + snprintf( stmp, sizeof(stmp), "%02X",Attrib); attrDataLbl->setText( tr(stmp) ); - sprintf(stmp,"%04X",AttAddress); + snprintf( stmp, sizeof(stmp), "%04X",AttAddress); attrAddrLbl->setText( tr(stmp) ); - sprintf(stmp,"%04X", palAddr ); + snprintf( stmp, sizeof(stmp), "%04X", palAddr ); palAddrLbl->setText( tr(stmp) ); } @@ -1341,25 +1341,25 @@ void ppuNameTableView_t::contextMenuEvent(QContextMenuEvent *event) redrawtables = true; - sprintf( stmp, "Open Tile $%04X in PPU &Viewer", tileAddr ); + snprintf( stmp, sizeof(stmp), "Open Tile $%04X in PPU &Viewer", tileAddr ); act = new QAction(tr(stmp), &menu); //act->setShortcut( QKeySequence(tr("V"))); connect( act, SIGNAL(triggered(void)), this, SLOT(openTilePpuViewer(void)) ); menu.addAction( act ); - sprintf( stmp, "Open &Tile Addr $%04X in Hex Editor", tileAddr ); + snprintf( stmp, sizeof(stmp), "Open &Tile Addr $%04X in Hex Editor", tileAddr ); act = new QAction(tr(stmp), &menu); //act->setShortcut( QKeySequence(tr("H"))); connect( act, SIGNAL(triggered(void)), this, SLOT(openTileAddrHexEdit(void)) ); menu.addAction( act ); - sprintf( stmp, "Open &Attr Addr $%04X in Hex Editor", atrbAddr ); + snprintf( stmp, sizeof(stmp), "Open &Attr Addr $%04X in Hex Editor", atrbAddr ); act = new QAction(tr(stmp), &menu); //act->setShortcut( QKeySequence(tr("H"))); connect( act, SIGNAL(triggered(void)), this, SLOT(openAtrbAddrHexEdit(void)) ); menu.addAction( act ); - sprintf( stmp, "Open &PPU Addr $%04X in Hex Editor", ppuAddr ); + snprintf( stmp, sizeof(stmp), "Open &PPU Addr $%04X in Hex Editor", ppuAddr ); act = new QAction(tr(stmp), &menu); //act->setShortcut( QKeySequence(tr("H"))); connect( act, SIGNAL(triggered(void)), this, SLOT(openPpuAddrHexEdit(void)) ); diff --git a/src/drivers/Qt/PaletteConf.cpp b/src/drivers/Qt/PaletteConf.cpp index 4c67002a..1baf7398 100644 --- a/src/drivers/Qt/PaletteConf.cpp +++ b/src/drivers/Qt/PaletteConf.cpp @@ -143,7 +143,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) connect(ntscFrame, SIGNAL(clicked(bool)), this, SLOT(use_NTSC_Changed(bool))); - sprintf(stmp, "Tint: %3i", tint); + snprintf(stmp, sizeof(stmp), "Tint: %3i", tint); tintFrame = new QGroupBox(tr(stmp)); hbox1 = new QHBoxLayout(); tintSlider = new QSlider(Qt::Horizontal); @@ -157,7 +157,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) tintFrame->setLayout(hbox1); hbox2->addWidget(tintFrame); - sprintf(stmp, "Hue: %3i", hue); + snprintf(stmp, sizeof(stmp), "Hue: %3i", hue); hueFrame = new QGroupBox(tr(stmp)); hbox1 = new QHBoxLayout(); hueSlider = new QSlider(Qt::Horizontal); @@ -190,7 +190,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) grid->setColumnStretch( 1, 40 ); grid->setColumnStretch( 2, 20 ); - sprintf(stmp, "Notch: %3i%%", palnotch); + snprintf(stmp, sizeof(stmp), "Notch: %3i%%", palnotch); notchFrame = new QGroupBox(tr(stmp)); #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) notchFrame->setMinimumWidth( notchFrame->fontMetrics().horizontalAdvance('2') * strlen(stmp) ); @@ -207,7 +207,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) hbox1->addWidget(notchSlider); notchFrame->setLayout(hbox1); - sprintf(stmp, "Saturation: %3i%%", palsaturation); + snprintf(stmp, sizeof(stmp), "Saturation: %3i%%", palsaturation); saturationFrame = new QGroupBox(tr(stmp)); #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) saturationFrame->setMinimumWidth( saturationFrame->fontMetrics().horizontalAdvance('2') * strlen(stmp) ); @@ -224,7 +224,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) hbox1->addWidget(saturationSlider); saturationFrame->setLayout(hbox1); - sprintf(stmp, "Sharpness: %3i%%", palsharpness*2); + snprintf(stmp, sizeof(stmp), "Sharpness: %3i%%", palsharpness*2); sharpnessFrame = new QGroupBox(tr(stmp)); #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) sharpnessFrame->setMinimumWidth( sharpnessFrame->fontMetrics().horizontalAdvance('2') * strlen(stmp) ); @@ -241,7 +241,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) hbox1->addWidget(sharpnessSlider); sharpnessFrame->setLayout(hbox1); - sprintf(stmp, "Contrast: %3i%%", palcontrast); + snprintf(stmp, sizeof(stmp), "Contrast: %3i%%", palcontrast); contrastFrame = new QGroupBox(tr(stmp)); #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) contrastFrame->setMinimumWidth( contrastFrame->fontMetrics().horizontalAdvance('2') * strlen(stmp) ); @@ -258,7 +258,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) hbox1->addWidget(contrastSlider); contrastFrame->setLayout(hbox1); - sprintf(stmp, "Brightness: %3i%%", palbrightness); + snprintf(stmp, sizeof(stmp), "Brightness: %3i%%", palbrightness); brightnessFrame = new QGroupBox(tr(stmp)); #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) brightnessFrame->setMinimumWidth( brightnessFrame->fontMetrics().horizontalAdvance('2') * strlen(stmp) ); @@ -361,7 +361,7 @@ void PaletteConfDialog_t::hueChanged(int v) int c, t; char stmp[64]; - sprintf(stmp, "Hue: %3i", v); + snprintf(stmp, sizeof(stmp), "Hue: %3i", v); hueFrame->setTitle(stmp); @@ -382,7 +382,7 @@ void PaletteConfDialog_t::tintChanged(int v) int c, h; char stmp[64]; - sprintf(stmp, "Tint: %3i", v); + snprintf(stmp, sizeof(stmp), "Tint: %3i", v); tintFrame->setTitle(stmp); @@ -653,7 +653,7 @@ void PaletteConfDialog_t::palNotchChanged(int value) { char stmp[64]; - sprintf( stmp, "Notch: %3i%%", value ); + snprintf( stmp, sizeof(stmp), "Notch: %3i%%", value ); notchFrame->setTitle( tr(stmp) ); palnotch = value; @@ -671,7 +671,7 @@ void PaletteConfDialog_t::palSaturationChanged(int value) { char stmp[64]; - sprintf( stmp, "Saturation: %3i%%", value ); + snprintf( stmp, sizeof(stmp), "Saturation: %3i%%", value ); saturationFrame->setTitle( tr(stmp) ); palsaturation = value; @@ -689,7 +689,7 @@ void PaletteConfDialog_t::palSharpnessChanged(int value) { char stmp[64]; - sprintf( stmp, "Sharpness: %3i%%", value*2 ); + snprintf( stmp, sizeof(stmp), "Sharpness: %3i%%", value*2 ); sharpnessFrame->setTitle( tr(stmp) ); palsharpness = value; @@ -707,7 +707,7 @@ void PaletteConfDialog_t::palContrastChanged(int value) { char stmp[64]; - sprintf( stmp, "Contrast: %3i%%", value ); + snprintf( stmp, sizeof(stmp), "Contrast: %3i%%", value ); contrastFrame->setTitle( tr(stmp) ); palcontrast = value; @@ -725,7 +725,7 @@ void PaletteConfDialog_t::palBrightnessChanged(int value) { char stmp[64]; - sprintf( stmp, "Brightness: %3i%%", value ); + snprintf( stmp, sizeof(stmp), "Brightness: %3i%%", value ); brightnessFrame->setTitle( tr(stmp) ); palbrightness = value; diff --git a/src/drivers/Qt/PaletteEditor.cpp b/src/drivers/Qt/PaletteEditor.cpp index b0c93deb..d4dc7fe4 100644 --- a/src/drivers/Qt/PaletteEditor.cpp +++ b/src/drivers/Qt/PaletteEditor.cpp @@ -232,7 +232,7 @@ void PaletteEditorDialog_t::updatePeriodic(void) chg = undoColorHistory.back(); - sprintf( stmp, "&Undo $%02X = rgb(%3i,%3i,%3i)", chg.palIdx, + snprintf( stmp, sizeof(stmp), "&Undo $%02X = rgb(%3i,%3i,%3i)", chg.palIdx, chg.newColor.red(), chg.newColor.green(), chg.newColor.blue() ); undoAct->setText( tr(stmp) ); @@ -249,7 +249,7 @@ void PaletteEditorDialog_t::updatePeriodic(void) chg = redoColorHistory.back(); - sprintf( stmp, "&Redo $%02X = rgb(%3i,%3i,%3i)", chg.palIdx, + snprintf( stmp, sizeof(stmp), "&Redo $%02X = rgb(%3i,%3i,%3i)", chg.palIdx, chg.newColor.red(), chg.newColor.green(), chg.newColor.blue() ); redoAct->setText( tr(stmp) ); @@ -798,7 +798,7 @@ void nesPaletteView::contextMenuEvent(QContextMenuEvent *event) update(); } - sprintf( stmp, "Edit Color %X%X", selCell.y(), selCell.x() ); + snprintf( stmp, sizeof(stmp), "Edit Color %X%X", selCell.y(), selCell.x() ); act = new QAction(tr(stmp), &menu); act->setShortcut( QKeySequence(tr("E"))); connect( act, SIGNAL(triggered(void)), this, SLOT(editSelColor(void)) ); @@ -947,7 +947,7 @@ nesColorPickerDialog_t::nesColorPickerDialog_t( int palIndex, QColor *c, QWidget style = this->style(); - sprintf( stmp, "Pick Palette Color $%02X", palIndex ); + snprintf( stmp, sizeof(stmp), "Pick Palette Color $%02X", palIndex ); setWindowTitle( stmp ); @@ -1220,7 +1220,7 @@ void nesPalettePickerView::contextMenuEvent(QContextMenuEvent *event) // //QActionGroup *group; // char stmp[64]; // -// sprintf( stmp, "Edit Color %X%X", selCell.y(), selCell.x() ); +// snprintf( stmp, sizeof(stmp), "Edit Color %X%X", selCell.y(), selCell.x() ); // act = new QAction(tr(stmp), &menu); // act->setShortcut( QKeySequence(tr("E"))); // connect( act, SIGNAL(triggered(void)), this, SLOT(editSelColor(void)) ); @@ -1341,7 +1341,7 @@ nesPalettePickerDialog::nesPalettePickerDialog( int idx, QWidget *parent) palIdx = idx; palAddr = 0x3F00 + palIdx; - sprintf( stmp, "Pick Palette Color for Address $%04X", palAddr ); + snprintf( stmp, sizeof(stmp), "Pick Palette Color for Address $%04X", palAddr ); setWindowTitle( tr(stmp) ); palOrigVal = READPAL_MOTHEROFALL(palIdx & 0x1F); diff --git a/src/drivers/Qt/RamSearch.cpp b/src/drivers/Qt/RamSearch.cpp index 3ac71b3f..f3390af7 100644 --- a/src/drivers/Qt/RamSearch.cpp +++ b/src/drivers/Qt/RamSearch.cpp @@ -2012,63 +2012,63 @@ void QRamSearchView::paintEvent(QPaintEvent *event) painter.fillRect(0, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, QColor("light blue")); } - sprintf(addrStr, "$%04X", loc->addr); + snprintf(addrStr, sizeof(addrStr), "$%04X", loc->addr); if (dpySize == 'd') { if (dpyType == 'h') { - sprintf(valStr, "0x%08X", loc->val.v32.u); - sprintf(prevStr, "0x%08X", loc->hist.back().v32.u); + snprintf(valStr, sizeof(valStr), "0x%08X", loc->val.v32.u); + snprintf(prevStr, sizeof(prevStr), "0x%08X", loc->hist.back().v32.u); } else if (dpyType == 'u') { - sprintf(valStr, "%u", loc->val.v32.u); - sprintf(prevStr, "%u", loc->hist.back().v32.u); + snprintf(valStr, sizeof(valStr), "%u", loc->val.v32.u); + snprintf(prevStr, sizeof(prevStr), "%u", loc->hist.back().v32.u); } else { - sprintf(valStr, "%i", loc->val.v32.i); - sprintf(prevStr, "%i", loc->hist.back().v32.i); + snprintf(valStr, sizeof(valStr), "%i", loc->val.v32.i); + snprintf(prevStr, sizeof(prevStr), "%i", loc->hist.back().v32.i); } } else if (dpySize == 'w') { if (dpyType == 'h') { - sprintf(valStr, "0x%04X", loc->val.v16.u); - sprintf(prevStr, "0x%04X", loc->hist.back().v16.u); + snprintf(valStr, sizeof(valStr), "0x%04X", loc->val.v16.u); + snprintf(prevStr, sizeof(prevStr), "0x%04X", loc->hist.back().v16.u); } else if (dpyType == 'u') { - sprintf(valStr, "%u", loc->val.v16.u); - sprintf(prevStr, "%u", loc->hist.back().v16.u); + snprintf(valStr, sizeof(valStr), "%u", loc->val.v16.u); + snprintf(prevStr, sizeof(prevStr), "%u", loc->hist.back().v16.u); } else { - sprintf(valStr, "%i", loc->val.v16.i); - sprintf(prevStr, "%i", loc->hist.back().v16.i); + snprintf(valStr, sizeof(valStr), "%i", loc->val.v16.i); + snprintf(prevStr, sizeof(prevStr), "%i", loc->hist.back().v16.i); } } else { if (dpyType == 'h') { - sprintf(valStr, "0x%02X", loc->val.v8.u); - sprintf(prevStr, "0x%02X", loc->hist.back().v8.u); + snprintf(valStr, sizeof(valStr), "0x%02X", loc->val.v8.u); + snprintf(prevStr, sizeof(prevStr), "0x%02X", loc->hist.back().v8.u); } else if (dpyType == 'u') { - sprintf(valStr, "%u", loc->val.v8.u); - sprintf(prevStr, "%u", loc->hist.back().v8.u); + snprintf(valStr, sizeof(valStr), "%u", loc->val.v8.u); + snprintf(prevStr, sizeof(prevStr), "%u", loc->hist.back().v8.u); } else { - sprintf(valStr, "%i", loc->val.v8.i); - sprintf(prevStr, "%i", loc->hist.back().v8.i); + snprintf(valStr, sizeof(valStr), "%i", loc->val.v8.i); + snprintf(prevStr, sizeof(prevStr), "%i", loc->hist.back().v8.i); } } - sprintf(chgStr, "%u", loc->chgCount); + snprintf(chgStr, sizeof(chgStr), "%u", loc->chgCount); for (i = 0; i < 4; i++) { diff --git a/src/drivers/Qt/RamWatch.cpp b/src/drivers/Qt/RamWatch.cpp index 775ca18a..e2899a32 100644 --- a/src/drivers/Qt/RamWatch.cpp +++ b/src/drivers/Qt/RamWatch.cpp @@ -403,11 +403,11 @@ void RamWatchDialog_t::updateRamWatchDisplay(void) { if ( rw->size > 1 ) { - sprintf (addrStr, "$%04X-$%04X", rw->addr, rw->addr + rw->size - 1); + snprintf (addrStr, sizeof(addrStr), "$%04X-$%04X", rw->addr, rw->addr + rw->size - 1); } else { - sprintf (addrStr, "$%04X", rw->addr); + snprintf (addrStr, sizeof(addrStr), "$%04X", rw->addr); } } @@ -424,37 +424,37 @@ void RamWatchDialog_t::updateRamWatchDisplay(void) { if (rw->type == 's') { - sprintf (valStr1, "%i", rw->val.i32); + snprintf (valStr1, sizeof(valStr1), "%i", rw->val.i32); } else { - sprintf (valStr1, "%u", rw->val.u32); + snprintf (valStr1, sizeof(valStr1), "%u", rw->val.u32); } - sprintf (valStr2, "0x%08X", rw->val.u32); + snprintf (valStr2, sizeof(valStr2), "0x%08X", rw->val.u32); } else if (rw->size == 2) { if (rw->type == 's') { - sprintf (valStr1, "%6i", rw->val.i16); + snprintf (valStr1, sizeof(valStr1), "%6i", rw->val.i16); } else { - sprintf (valStr1, "%6u", rw->val.u16); + snprintf (valStr1, sizeof(valStr1), "%6u", rw->val.u16); } - sprintf (valStr2, "0x%04X", rw->val.u16); + snprintf (valStr2, sizeof(valStr2), "0x%04X", rw->val.u16); } else { if (rw->type == 's') { - sprintf (valStr1, "%6i", rw->val.i8); + snprintf (valStr1, sizeof(valStr1), "%6i", rw->val.i8); } else { - sprintf (valStr1, "%6u", rw->val.u8); + snprintf (valStr1, sizeof(valStr1), "%6u", rw->val.u8); } - sprintf (valStr2, "0x%02X", rw->val.u8); + snprintf (valStr2, sizeof(valStr2), "0x%02X", rw->val.u8); } } @@ -851,7 +851,7 @@ void RamWatchDialog_t::openWatchEditWindow( ramWatch_t *rw, int mode) if ( (rw->addr >= 0) && !rw->isSep ) { - sprintf( stmp, "%04X", rw->addr ); + snprintf( stmp, sizeof(stmp), "%04X", rw->addr ); addrEntry->setText( tr(stmp) ); } else diff --git a/src/drivers/Qt/StateRecorderConf.cpp b/src/drivers/Qt/StateRecorderConf.cpp index d0cfcba3..3775ed5a 100644 --- a/src/drivers/Qt/StateRecorderConf.cpp +++ b/src/drivers/Qt/StateRecorderConf.cpp @@ -606,7 +606,7 @@ void StateRecorderDialog_t::recalcMemoryUsage(void) int inumSnaps = static_cast( fnumSnaps + 0.5f ); - sprintf( stmp, "%i", inumSnaps ); + snprintf( stmp, sizeof(stmp), "%i", inumSnaps ); numSnapsLbl->setText( tr(stmp) ); @@ -642,11 +642,11 @@ void StateRecorderDialog_t::recalcMemoryUsage(void) if (fsnapSize >= oneKiloByte) { - sprintf( stmp, "%.02f kB", fsnapSize / oneKiloByte ); + snprintf( stmp, sizeof(stmp), "%.02f kB", fsnapSize / oneKiloByte ); } else { - sprintf( stmp, "%.0f B", fsnapSize ); + snprintf( stmp, sizeof(stmp), "%.0f B", fsnapSize ); } snapMemSizeLbl->setText( tr(stmp) ); @@ -655,20 +655,20 @@ void StateRecorderDialog_t::recalcMemoryUsage(void) if (ftotalSize >= oneMegaByte) { - sprintf( stmp, "%.02f MB", ftotalSize / oneMegaByte ); + snprintf( stmp, sizeof(stmp), "%.02f MB", ftotalSize / oneMegaByte ); } else if (ftotalSize >= oneKiloByte) { - sprintf( stmp, "%.02f kB", ftotalSize / oneKiloByte ); + snprintf( stmp, sizeof(stmp), "%.02f kB", ftotalSize / oneKiloByte ); } else { - sprintf( stmp, "%.0f B", ftotalSize ); + snprintf( stmp, sizeof(stmp), "%.0f B", ftotalSize ); } totalMemUsageLbl->setText( tr(stmp) ); - sprintf( stmp, "%.02f ms", saveTimeMs); + snprintf( stmp, sizeof(stmp), "%.02f ms", saveTimeMs); saveTimeLbl->setText( tr(stmp) ); } //---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/SymbolicDebug.cpp b/src/drivers/Qt/SymbolicDebug.cpp index fc83f733..535c82b9 100644 --- a/src/drivers/Qt/SymbolicDebug.cpp +++ b/src/drivers/Qt/SymbolicDebug.cpp @@ -31,6 +31,7 @@ #include "../../ines.h" #include "../../asm.h" #include "../../x6502.h" +#include "utils/StringBuilder.h" #include "Qt/fceuWrapper.h" #include "Qt/SymbolicDebug.h" @@ -42,6 +43,7 @@ debugSymbol_t *replaceSymbols( int flags, int addr, char *str ) { debugSymbol_t *sym; + StringBuilder sb(str); if ( addr >= 0x8000 ) { @@ -59,36 +61,16 @@ debugSymbol_t *replaceSymbols( int flags, int addr, char *str ) } } + if ( !sym || !( flags & ASM_DEBUG_REPLACE ) ) + { + sb << sb_addr( addr, flags & ASM_DEBUG_ADDR_02X ? 2 : 4 ); + + if ( sym ) + sb << ' '; + } + if ( sym ) - { - if ( flags & ASM_DEBUG_REPLACE ) - { - strcpy( str, sym->name().c_str() ); - } - else - { - if ( flags & ASM_DEBUG_ADDR_02X ) - { - sprintf( str, "$%02X ", addr ); - } - else - { - sprintf( str, "$%04X ", addr ); - } - strcat( str, sym->name().c_str() ); - } - } - else - { - if ( flags & ASM_DEBUG_ADDR_02X ) - { - sprintf( str, "$%02X", addr ); - } - else - { - sprintf( str, "$%04X", addr ); - } - } + sb << sym->name().c_str(); return sym; } @@ -97,10 +79,12 @@ int DisassembleWithDebug(int addr, uint8_t *opcode, int flags, char *str, debugS { debugSymbol_t *sym = NULL; debugSymbol_t *sym2 = NULL; - static char chr[8]={0}; + const char *chr; + char indReg; uint16_t tmp,tmp2; char stmp[128], stmp2[128]; bool symDebugEnable, showTrace; + StringBuilder sb(str); symDebugEnable = (flags & ASM_DEBUG_SYMS ) ? true : false; showTrace = (flags & ASM_DEBUG_TRACES) ? true : false; @@ -133,7 +117,7 @@ int DisassembleWithDebug(int addr, uint8_t *opcode, int flags, char *str, debugS #ifdef BRK_3BYTE_HACK case 0x00: - sprintf(str,"BRK %02X %02X", opcode[1], opcode[2]); + snprintf(str, sizeof(str), "BRK %02X %02X", opcode[1], opcode[2]); break; #else case 0x00: strcpy(str,"BRK"); break; @@ -170,321 +154,309 @@ int DisassembleWithDebug(int addr, uint8_t *opcode, int flags, char *str, debugS case 0xF8: strcpy(str,"SED"); break; //(Indirect,X) - case 0x01: strcpy(chr,"ORA"); goto _indirectx; - case 0x21: strcpy(chr,"AND"); goto _indirectx; - case 0x41: strcpy(chr,"EOR"); goto _indirectx; - case 0x61: strcpy(chr,"ADC"); goto _indirectx; - case 0x81: strcpy(chr,"STA"); goto _indirectx; - case 0xA1: strcpy(chr,"LDA"); goto _indirectx; - case 0xC1: strcpy(chr,"CMP"); goto _indirectx; - case 0xE1: strcpy(chr,"SBC"); goto _indirectx; + case 0x01: chr = "ORA"; goto _indirectx; + case 0x21: chr = "AND"; goto _indirectx; + case 0x41: chr = "EOR"; goto _indirectx; + case 0x61: chr = "ADC"; goto _indirectx; + case 0x81: chr = "STA"; goto _indirectx; + case 0xA1: chr = "LDA"; goto _indirectx; + case 0xC1: chr = "CMP"; goto _indirectx; + case 0xE1: chr = "SBC"; goto _indirectx; _indirectx: indirectX(tmp); + indReg = 'X'; + _indirect: if ( symDebugEnable ) - { sym = replaceSymbols( flags, tmp, stmp ); - showTrace - ? sprintf(str,"%s ($%02X,X) @ %s = #$%02X", chr,opcode[1],stmp,GetMem(tmp)) - : sprintf(str,"%s ($%02X,X)", chr,opcode[1]); - } - else + + sb << chr << " (" << sb_addr(opcode[1], 2) << ',' << indReg << ')'; + + if (showTrace) { - showTrace - ? sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) - : sprintf(str,"%s ($%02X,X)", chr,opcode[1]); + sb << " @ "; + if (symDebugEnable) + sb << stmp; + else + sb << sb_addr(tmp); + + sb << " = " << sb_lit(GetMem(tmp)); } break; //Zero Page - case 0x05: strcpy(chr,"ORA"); goto _zeropage; - case 0x06: strcpy(chr,"ASL"); goto _zeropage; - case 0x24: strcpy(chr,"BIT"); goto _zeropage; - case 0x25: strcpy(chr,"AND"); goto _zeropage; - case 0x26: strcpy(chr,"ROL"); goto _zeropage; - case 0x45: strcpy(chr,"EOR"); goto _zeropage; - case 0x46: strcpy(chr,"LSR"); goto _zeropage; - case 0x65: strcpy(chr,"ADC"); goto _zeropage; - case 0x66: strcpy(chr,"ROR"); goto _zeropage; - case 0x84: strcpy(chr,"STY"); goto _zeropage; - case 0x85: strcpy(chr,"STA"); goto _zeropage; - case 0x86: strcpy(chr,"STX"); goto _zeropage; - case 0xA4: strcpy(chr,"LDY"); goto _zeropage; - case 0xA5: strcpy(chr,"LDA"); goto _zeropage; - case 0xA6: strcpy(chr,"LDX"); goto _zeropage; - case 0xC4: strcpy(chr,"CPY"); goto _zeropage; - case 0xC5: strcpy(chr,"CMP"); goto _zeropage; - case 0xC6: strcpy(chr,"DEC"); goto _zeropage; - case 0xE4: strcpy(chr,"CPX"); goto _zeropage; - case 0xE5: strcpy(chr,"SBC"); goto _zeropage; - case 0xE6: strcpy(chr,"INC"); goto _zeropage; + case 0x05: chr = "ORA"; goto _zeropage; + case 0x06: chr = "ASL"; goto _zeropage; + case 0x24: chr = "BIT"; goto _zeropage; + case 0x25: chr = "AND"; goto _zeropage; + case 0x26: chr = "ROL"; goto _zeropage; + case 0x45: chr = "EOR"; goto _zeropage; + case 0x46: chr = "LSR"; goto _zeropage; + case 0x65: chr = "ADC"; goto _zeropage; + case 0x66: chr = "ROR"; goto _zeropage; + case 0x84: chr = "STY"; goto _zeropage; + case 0x85: chr = "STA"; goto _zeropage; + case 0x86: chr = "STX"; goto _zeropage; + case 0xA4: chr = "LDY"; goto _zeropage; + case 0xA5: chr = "LDA"; goto _zeropage; + case 0xA6: chr = "LDX"; goto _zeropage; + case 0xC4: chr = "CPY"; goto _zeropage; + case 0xC5: chr = "CMP"; goto _zeropage; + case 0xC6: chr = "DEC"; goto _zeropage; + case 0xE4: chr = "CPX"; goto _zeropage; + case 0xE5: chr = "SBC"; goto _zeropage; + case 0xE6: chr = "INC"; goto _zeropage; _zeropage: // ################################## Start of SP CODE ########################### // Change width to %04X // don't! + + sb << chr << ' '; if ( symDebugEnable ) { sym = replaceSymbols( flags | ASM_DEBUG_ADDR_02X, opcode[1], stmp ); - showTrace - ? sprintf(str,"%s %s = #$%02X", chr,stmp,GetMem(opcode[1])) - : sprintf(str,"%s %s", chr,stmp); + sb << stmp; } else - { - showTrace - ? sprintf(str,"%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1])) - : sprintf(str,"%s $%02X", chr,opcode[1]); - } + sb << sb_addr(opcode[1], 2); + + if (showTrace) + sb << " = " << sb_lit(GetMem(opcode[1])); + // ################################## End of SP CODE ########################### break; //#Immediate - case 0x09: strcpy(chr,"ORA"); goto _immediate; - case 0x29: strcpy(chr,"AND"); goto _immediate; - case 0x49: strcpy(chr,"EOR"); goto _immediate; - case 0x69: strcpy(chr,"ADC"); goto _immediate; - //case 0x89: strcpy(chr,"STA"); goto _immediate; //baka, no STA #imm!! - case 0xA0: strcpy(chr,"LDY"); goto _immediate; - case 0xA2: strcpy(chr,"LDX"); goto _immediate; - case 0xA9: strcpy(chr,"LDA"); goto _immediate; - case 0xC0: strcpy(chr,"CPY"); goto _immediate; - case 0xC9: strcpy(chr,"CMP"); goto _immediate; - case 0xE0: strcpy(chr,"CPX"); goto _immediate; - case 0xE9: strcpy(chr,"SBC"); goto _immediate; + case 0x09: chr = "ORA"; goto _immediate; + case 0x29: chr = "AND"; goto _immediate; + case 0x49: chr = "EOR"; goto _immediate; + case 0x69: chr = "ADC"; goto _immediate; + //case 0x89: chr = "STA"; goto _immediate; //baka, no STA #imm!! + case 0xA0: chr = "LDY"; goto _immediate; + case 0xA2: chr = "LDX"; goto _immediate; + case 0xA9: chr = "LDA"; goto _immediate; + case 0xC0: chr = "CPY"; goto _immediate; + case 0xC9: chr = "CMP"; goto _immediate; + case 0xE0: chr = "CPX"; goto _immediate; + case 0xE9: chr = "SBC"; goto _immediate; _immediate: - sprintf(str,"%s #$%02X", chr,opcode[1]); + sb << chr << ' ' << sb_lit(opcode[1]); break; //Absolute - case 0x0D: strcpy(chr,"ORA"); goto _absolute; - case 0x0E: strcpy(chr,"ASL"); goto _absolute; - case 0x2C: strcpy(chr,"BIT"); goto _absolute; - case 0x2D: strcpy(chr,"AND"); goto _absolute; - case 0x2E: strcpy(chr,"ROL"); goto _absolute; - case 0x4D: strcpy(chr,"EOR"); goto _absolute; - case 0x4E: strcpy(chr,"LSR"); goto _absolute; - case 0x6D: strcpy(chr,"ADC"); goto _absolute; - case 0x6E: strcpy(chr,"ROR"); goto _absolute; - case 0x8C: strcpy(chr,"STY"); goto _absolute; - case 0x8D: strcpy(chr,"STA"); goto _absolute; - case 0x8E: strcpy(chr,"STX"); goto _absolute; - case 0xAC: strcpy(chr,"LDY"); goto _absolute; - case 0xAD: strcpy(chr,"LDA"); goto _absolute; - case 0xAE: strcpy(chr,"LDX"); goto _absolute; - case 0xCC: strcpy(chr,"CPY"); goto _absolute; - case 0xCD: strcpy(chr,"CMP"); goto _absolute; - case 0xCE: strcpy(chr,"DEC"); goto _absolute; - case 0xEC: strcpy(chr,"CPX"); goto _absolute; - case 0xED: strcpy(chr,"SBC"); goto _absolute; - case 0xEE: strcpy(chr,"INC"); goto _absolute; + case 0x0D: chr = "ORA"; goto _absolute; + case 0x0E: chr = "ASL"; goto _absolute; + case 0x2C: chr = "BIT"; goto _absolute; + case 0x2D: chr = "AND"; goto _absolute; + case 0x2E: chr = "ROL"; goto _absolute; + case 0x4D: chr = "EOR"; goto _absolute; + case 0x4E: chr = "LSR"; goto _absolute; + case 0x6D: chr = "ADC"; goto _absolute; + case 0x6E: chr = "ROR"; goto _absolute; + case 0x8C: chr = "STY"; goto _absolute; + case 0x8D: chr = "STA"; goto _absolute; + case 0x8E: chr = "STX"; goto _absolute; + case 0xAC: chr = "LDY"; goto _absolute; + case 0xAD: chr = "LDA"; goto _absolute; + case 0xAE: chr = "LDX"; goto _absolute; + case 0xCC: chr = "CPY"; goto _absolute; + case 0xCD: chr = "CMP"; goto _absolute; + case 0xCE: chr = "DEC"; goto _absolute; + case 0xEC: chr = "CPX"; goto _absolute; + case 0xED: chr = "SBC"; goto _absolute; + case 0xEE: chr = "INC"; goto _absolute; _absolute: absolute(tmp); + sb << chr << ' '; if ( symDebugEnable ) { sym = replaceSymbols( flags, tmp, stmp ); - showTrace - ? sprintf(str,"%s %s = #$%02X", chr,stmp,GetMem(tmp)) - : sprintf(str,"%s %s", chr,stmp); + sb << stmp; } else - { - showTrace - ? sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp)) - : sprintf(str,"%s $%04X", chr,tmp); - } + sb << sb_addr(tmp); + + if (showTrace) + sb << " = " << sb_lit(GetMem(tmp)); + break; //branches - case 0x10: strcpy(chr,"BPL"); goto _branch; - case 0x30: strcpy(chr,"BMI"); goto _branch; - case 0x50: strcpy(chr,"BVC"); goto _branch; - case 0x70: strcpy(chr,"BVS"); goto _branch; - case 0x90: strcpy(chr,"BCC"); goto _branch; - case 0xB0: strcpy(chr,"BCS"); goto _branch; - case 0xD0: strcpy(chr,"BNE"); goto _branch; - case 0xF0: strcpy(chr,"BEQ"); goto _branch; + case 0x10: chr = "BPL"; goto _branch; + case 0x30: chr = "BMI"; goto _branch; + case 0x50: chr = "BVC"; goto _branch; + case 0x70: chr = "BVS"; goto _branch; + case 0x90: chr = "BCC"; goto _branch; + case 0xB0: chr = "BCS"; goto _branch; + case 0xD0: chr = "BNE"; goto _branch; + case 0xF0: chr = "BEQ"; goto _branch; _branch: relative(tmp); + sb << chr << ' '; if ( symDebugEnable ) { sym = replaceSymbols( flags, tmp, stmp ); - sprintf(str,"%s %s", chr,stmp); + sb << stmp; } else - { - sprintf(str,"%s $%04X", chr,tmp); - } + sb << sb_addr(tmp); + break; //(Indirect),Y - case 0x11: strcpy(chr,"ORA"); goto _indirecty; - case 0x31: strcpy(chr,"AND"); goto _indirecty; - case 0x51: strcpy(chr,"EOR"); goto _indirecty; - case 0x71: strcpy(chr,"ADC"); goto _indirecty; - case 0x91: strcpy(chr,"STA"); goto _indirecty; - case 0xB1: strcpy(chr,"LDA"); goto _indirecty; - case 0xD1: strcpy(chr,"CMP"); goto _indirecty; - case 0xF1: strcpy(chr,"SBC"); goto _indirecty; + case 0x11: chr = "ORA"; goto _indirecty; + case 0x31: chr = "AND"; goto _indirecty; + case 0x51: chr = "EOR"; goto _indirecty; + case 0x71: chr = "ADC"; goto _indirecty; + case 0x91: chr = "STA"; goto _indirecty; + case 0xB1: chr = "LDA"; goto _indirecty; + case 0xD1: chr = "CMP"; goto _indirecty; + case 0xF1: chr = "SBC"; goto _indirecty; _indirecty: indirectY(tmp); + indReg = 'Y'; - if ( symDebugEnable ) - { - sym = replaceSymbols( flags, tmp, stmp ); - showTrace - ? sprintf(str,"%s ($%02X),Y @ %s = #$%02X", chr,opcode[1],stmp,GetMem(tmp)) - : sprintf(str,"%s ($%02X),Y", chr,opcode[1]); - } - else - { - showTrace - ? sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) - : sprintf(str,"%s ($%02X),Y", chr,opcode[1]); - } - break; + goto _indirect; //Zero Page,X - case 0x15: strcpy(chr,"ORA"); goto _zeropagex; - case 0x16: strcpy(chr,"ASL"); goto _zeropagex; - case 0x35: strcpy(chr,"AND"); goto _zeropagex; - case 0x36: strcpy(chr,"ROL"); goto _zeropagex; - case 0x55: strcpy(chr,"EOR"); goto _zeropagex; - case 0x56: strcpy(chr,"LSR"); goto _zeropagex; - case 0x75: strcpy(chr,"ADC"); goto _zeropagex; - case 0x76: strcpy(chr,"ROR"); goto _zeropagex; - case 0x94: strcpy(chr,"STY"); goto _zeropagex; - case 0x95: strcpy(chr,"STA"); goto _zeropagex; - case 0xB4: strcpy(chr,"LDY"); goto _zeropagex; - case 0xB5: strcpy(chr,"LDA"); goto _zeropagex; - case 0xD5: strcpy(chr,"CMP"); goto _zeropagex; - case 0xD6: strcpy(chr,"DEC"); goto _zeropagex; - case 0xF5: strcpy(chr,"SBC"); goto _zeropagex; - case 0xF6: strcpy(chr,"INC"); goto _zeropagex; + case 0x15: chr = "ORA"; goto _zeropagex; + case 0x16: chr = "ASL"; goto _zeropagex; + case 0x35: chr = "AND"; goto _zeropagex; + case 0x36: chr = "ROL"; goto _zeropagex; + case 0x55: chr = "EOR"; goto _zeropagex; + case 0x56: chr = "LSR"; goto _zeropagex; + case 0x75: chr = "ADC"; goto _zeropagex; + case 0x76: chr = "ROR"; goto _zeropagex; + case 0x94: chr = "STY"; goto _zeropagex; + case 0x95: chr = "STA"; goto _zeropagex; + case 0xB4: chr = "LDY"; goto _zeropagex; + case 0xB5: chr = "LDA"; goto _zeropagex; + case 0xD5: chr = "CMP"; goto _zeropagex; + case 0xD6: chr = "DEC"; goto _zeropagex; + case 0xF5: chr = "SBC"; goto _zeropagex; + case 0xF6: chr = "INC"; goto _zeropagex; _zeropagex: zpIndex(tmp,RX); + indReg = 'X'; + + _indexed: // ################################## Start of SP CODE ########################### // Change width to %04X // don't! if ( symDebugEnable ) - { sym = replaceSymbols( flags, tmp, stmp ); - showTrace - ? sprintf(str,"%s $%02X,X @ %s = #$%02X", chr,opcode[1],stmp,GetMem(tmp)) - : sprintf(str,"%s $%02X,X", chr,opcode[1]); - } - else + + sb << chr << ' ' << sb_addr(opcode[1], 2) << ',' << indReg; + if (showTrace) { - showTrace - ? sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) - : sprintf(str,"%s $%02X,X", chr,opcode[1]); + sb << " @ "; + if (symDebugEnable) + sb << stmp; + else + sb << sb_addr(tmp); + + sb << " = " << sb_lit(GetMem(tmp)); } // ################################## End of SP CODE ########################### break; //Absolute,Y - case 0x19: strcpy(chr,"ORA"); goto _absolutey; - case 0x39: strcpy(chr,"AND"); goto _absolutey; - case 0x59: strcpy(chr,"EOR"); goto _absolutey; - case 0x79: strcpy(chr,"ADC"); goto _absolutey; - case 0x99: strcpy(chr,"STA"); goto _absolutey; - case 0xB9: strcpy(chr,"LDA"); goto _absolutey; - case 0xBE: strcpy(chr,"LDX"); goto _absolutey; - case 0xD9: strcpy(chr,"CMP"); goto _absolutey; - case 0xF9: strcpy(chr,"SBC"); goto _absolutey; + case 0x19: chr = "ORA"; goto _absolutey; + case 0x39: chr = "AND"; goto _absolutey; + case 0x59: chr = "EOR"; goto _absolutey; + case 0x79: chr = "ADC"; goto _absolutey; + case 0x99: chr = "STA"; goto _absolutey; + case 0xB9: chr = "LDA"; goto _absolutey; + case 0xBE: chr = "LDX"; goto _absolutey; + case 0xD9: chr = "CMP"; goto _absolutey; + case 0xF9: chr = "SBC"; goto _absolutey; _absolutey: absolute(tmp); tmp2=(tmp+RY); + indReg = 'Y'; + + _absindexed: + sb << chr << ' '; if ( symDebugEnable ) { sym = replaceSymbols( flags, tmp , stmp ); sym2 = replaceSymbols( flags, tmp2, stmp2 ); - showTrace - ? sprintf(str,"%s %s,Y @ %s = #$%02X", chr,stmp,stmp2,GetMem(tmp2)) - : sprintf(str,"%s %s,Y", chr,stmp); + sb << stmp; } else + sb << sb_addr(tmp); + + sb << ',' << indReg; + + if (showTrace) { - showTrace - ? sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)) - : sprintf(str,"%s $%04X,Y", chr,tmp); + sb << " @ "; + if (symDebugEnable) + sb << stmp2; + else + sb << sb_addr(tmp2); + + sb << " = " << sb_lit(GetMem(tmp2)); } + break; //Absolute,X - case 0x1D: strcpy(chr,"ORA"); goto _absolutex; - case 0x1E: strcpy(chr,"ASL"); goto _absolutex; - case 0x3D: strcpy(chr,"AND"); goto _absolutex; - case 0x3E: strcpy(chr,"ROL"); goto _absolutex; - case 0x5D: strcpy(chr,"EOR"); goto _absolutex; - case 0x5E: strcpy(chr,"LSR"); goto _absolutex; - case 0x7D: strcpy(chr,"ADC"); goto _absolutex; - case 0x7E: strcpy(chr,"ROR"); goto _absolutex; - case 0x9D: strcpy(chr,"STA"); goto _absolutex; - case 0xBC: strcpy(chr,"LDY"); goto _absolutex; - case 0xBD: strcpy(chr,"LDA"); goto _absolutex; - case 0xDD: strcpy(chr,"CMP"); goto _absolutex; - case 0xDE: strcpy(chr,"DEC"); goto _absolutex; - case 0xFD: strcpy(chr,"SBC"); goto _absolutex; - case 0xFE: strcpy(chr,"INC"); goto _absolutex; + case 0x1D: chr = "ORA"; goto _absolutex; + case 0x1E: chr = "ASL"; goto _absolutex; + case 0x3D: chr = "AND"; goto _absolutex; + case 0x3E: chr = "ROL"; goto _absolutex; + case 0x5D: chr = "EOR"; goto _absolutex; + case 0x5E: chr = "LSR"; goto _absolutex; + case 0x7D: chr = "ADC"; goto _absolutex; + case 0x7E: chr = "ROR"; goto _absolutex; + case 0x9D: chr = "STA"; goto _absolutex; + case 0xBC: chr = "LDY"; goto _absolutex; + case 0xBD: chr = "LDA"; goto _absolutex; + case 0xDD: chr = "CMP"; goto _absolutex; + case 0xDE: chr = "DEC"; goto _absolutex; + case 0xFD: chr = "SBC"; goto _absolutex; + case 0xFE: chr = "INC"; goto _absolutex; _absolutex: absolute(tmp); tmp2=(tmp+RX); - if ( symDebugEnable ) - { - sym = replaceSymbols( flags, tmp , stmp ); - sym2 = replaceSymbols( flags, tmp2, stmp2 ); - showTrace - ? sprintf(str,"%s %s,X @ %s = #$%02X", chr,stmp,stmp2,GetMem(tmp2)) - : sprintf(str,"%s %s,X", chr,stmp); - } - else - { - showTrace - ? sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)) - : sprintf(str,"%s $%04X,X", chr,tmp); - } - break; + indReg = 'X'; + + goto _absindexed; //jumps - case 0x20: strcpy(chr,"JSR"); goto _jump; - case 0x4C: strcpy(chr,"JMP"); goto _jump; - case 0x6C: absolute(tmp); sprintf(str,"JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break; + case 0x20: chr = "JSR"; goto _jump; + case 0x4C: chr = "JMP"; goto _jump; _jump: absolute(tmp); - if ( symDebugEnable ) + sb << chr << ' '; + if (symDebugEnable) { - sym = replaceSymbols( flags, tmp, stmp ); - sprintf(str,"%s %s", chr,stmp); + sym = replaceSymbols(flags, tmp, stmp); + sb << stmp; } else - { - sprintf(str,"%s $%04X", chr,tmp); - } + sb << sb_addr(tmp); + + break; + + case 0x6C: + absolute(tmp); + + sb << "JMP (" << sb_addr(tmp); + sb << ") = " << sb_addr(GetMem(tmp) | GetMem(tmp + 1) << 8); + break; //Zero Page,Y - case 0x96: strcpy(chr,"STX"); goto _zeropagey; - case 0xB6: strcpy(chr,"LDX"); goto _zeropagey; + case 0x96: chr = "STX"; goto _zeropagey; + case 0xB6: chr = "LDX"; goto _zeropagey; _zeropagey: zpIndex(tmp,RY); - // ################################## Start of SP CODE ########################### - // Change width to %04X // don't! - if ( symDebugEnable ) - { - sym = replaceSymbols( flags, tmp, stmp ); - showTrace - ? sprintf(str,"%s $%02X,Y @ %s = #$%02X", chr,opcode[1],stmp,GetMem(tmp)) - : sprintf(str,"%s $%02X,Y", chr,opcode[1]); - } - else - { - showTrace - ? sprintf(str,"%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) - : sprintf(str,"%s $%02X,Y", chr,opcode[1]); - } - // ################################## End of SP CODE ########################### - break; + indReg = 'Y'; + + goto _indexed; //UNDEFINED default: strcpy(str,"ERROR"); break; @@ -727,7 +699,7 @@ void SymbolEditWindow::setAddr( int addrIn ) addr = addrIn; - sprintf( stmp, "%04X", addr ); + snprintf( stmp, sizeof(stmp), "%04X", addr ); addrEntry->setText( tr(stmp) ); @@ -949,7 +921,7 @@ void SymbolEditWindow::determineArrayStart(void) if ( (val >= 0) && (val < 256) ) { - sprintf( digits, "%02X", val ); + snprintf( digits, sizeof(digits), "%02X", val ); arrayInit->setText( tr(digits) ); } diff --git a/src/drivers/Qt/TimingConf.cpp b/src/drivers/Qt/TimingConf.cpp index e442d779..bfb59bc9 100644 --- a/src/drivers/Qt/TimingConf.cpp +++ b/src/drivers/Qt/TimingConf.cpp @@ -329,6 +329,20 @@ void TimingConfDialog_t::saveValues(void) #endif } //---------------------------------------------------------------------------- +QString TimingConfDialog_t::getSchedPrioErrorMsg(const char* funcName, int errorCode) +{ + QString msg = QString("Error: system call setPriority Failed\nReason: ") + QString(strerror(errorCode)) + QString("\n"); +#ifdef __linux__ + msg += "Ensure that your system has the proper resource permissions set in the file:\n\n"; + msg += " /etc/security/limits.conf \n\n"; + msg += "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"; + msg += "* - priority 99 \n"; + msg += "* - rtprio 99 \n"; + msg += "* - nice -20 \n"; +#endif + return msg; +} +//---------------------------------------------------------------------------- void TimingConfDialog_t::emuSchedNiceChange(int val) { #ifndef WIN32 @@ -339,19 +353,9 @@ void TimingConfDialog_t::emuSchedNiceChange(int val) FCEU_WRAPPER_LOCK(); if (consoleWindow->emulatorThread->setNicePriority(-val)) { - char msg[1024]; - - sprintf(msg, "Error: system call setPriority Failed\nReason: %s\n", strerror(errno)); -#ifdef __linux__ - strcat(msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); - strcat(msg, " /etc/security/limits.conf \n\n"); - strcat(msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); - strcat(msg, "* - priority 99 \n"); - strcat(msg, "* - rtprio 99 \n"); - strcat(msg, "* - nice -20 \n"); -#endif - printf("%s\n", msg); - consoleWindow->QueueErrorMsgWindow(msg); + QString msg = getSchedPrioErrorMsg("setPriority", errno); + printf("%s\n", msg.toLocal8Bit().constData()); + consoleWindow->QueueErrorMsgWindow(msg.toLocal8Bit().constData()); updateSliderValues(); } FCEU_WRAPPER_UNLOCK(); @@ -377,19 +381,9 @@ void TimingConfDialog_t::emuSchedPrioChange(int val) if (consoleWindow->emulatorThread->setSchedParam(policy, val)) { - char msg[1024]; - - sprintf(msg, "Error: system call pthread_setschedparam Failed\nReason: %s\n", strerror(errno)); -#ifdef __linux__ - strcat(msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); - strcat(msg, " /etc/security/limits.conf \n\n"); - strcat(msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); - strcat(msg, "* - priority 99 \n"); - strcat(msg, "* - rtprio 99 \n"); - strcat(msg, "* - nice -20 \n"); -#endif - printf("%s\n", msg); - consoleWindow->QueueErrorMsgWindow(msg); + QString msg = getSchedPrioErrorMsg("pthread_setschedparam", errno); + printf("%s\n", msg.toLocal8Bit().constData()); + consoleWindow->QueueErrorMsgWindow(msg.toLocal8Bit().constData()); updateSliderValues(); } FCEU_WRAPPER_UNLOCK(); @@ -412,19 +406,9 @@ void TimingConfDialog_t::emuSchedPolicyChange(int index) if (consoleWindow->emulatorThread->setSchedParam(policy, prio)) { - char msg[1024]; - - sprintf(msg, "Error: system call pthread_setschedparam Failed\nReason: %s\n", strerror(errno)); -#ifdef __linux__ - strcat(msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); - strcat(msg, " /etc/security/limits.conf \n\n"); - strcat(msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); - strcat(msg, "* - priority 99 \n"); - strcat(msg, "* - rtprio 99 \n"); - strcat(msg, "* - nice -20 \n"); -#endif - printf("%s\n", msg); - consoleWindow->QueueErrorMsgWindow(msg); + QString msg = getSchedPrioErrorMsg("pthread_setschedparam", errno); + printf("%s\n", msg.toLocal8Bit().constData()); + consoleWindow->QueueErrorMsgWindow(msg.toLocal8Bit().constData()); } updatePolicyBox(); @@ -444,19 +428,9 @@ void TimingConfDialog_t::guiSchedNiceChange(int val) FCEU_WRAPPER_LOCK(); if (consoleWindow->setNicePriority(-val)) { - char msg[1024]; - - sprintf(msg, "Error: system call setPriority Failed\nReason: %s\n", strerror(errno)); -#ifdef __linux__ - strcat(msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); - strcat(msg, " /etc/security/limits.conf \n\n"); - strcat(msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); - strcat(msg, "* - priority 99 \n"); - strcat(msg, "* - rtprio 99 \n"); - strcat(msg, "* - nice -20 \n"); -#endif - printf("%s\n", msg); - consoleWindow->QueueErrorMsgWindow(msg); + QString msg = getSchedPrioErrorMsg("setPriority", errno); + printf("%s\n", msg.toLocal8Bit().constData()); + consoleWindow->QueueErrorMsgWindow(msg.toLocal8Bit().constData()); updateSliderValues(); } FCEU_WRAPPER_UNLOCK(); @@ -480,19 +454,9 @@ void TimingConfDialog_t::guiSchedPrioChange(int val) if (consoleWindow->setSchedParam(policy, val)) { - char msg[1024]; - - sprintf(msg, "Error: system call pthread_setschedparam Failed\nReason: %s\n", strerror(errno)); -#ifdef __linux__ - strcat(msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); - strcat(msg, " /etc/security/limits.conf \n\n"); - strcat(msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); - strcat(msg, "* - priority 99 \n"); - strcat(msg, "* - rtprio 99 \n"); - strcat(msg, "* - nice -20 \n"); -#endif - printf("%s\n", msg); - consoleWindow->QueueErrorMsgWindow(msg); + QString msg = getSchedPrioErrorMsg("pthread_setschedparam", errno); + printf("%s\n", msg.toLocal8Bit().constData()); + consoleWindow->QueueErrorMsgWindow(msg.toLocal8Bit().constData()); updateSliderValues(); } FCEU_WRAPPER_UNLOCK(); @@ -515,19 +479,9 @@ void TimingConfDialog_t::guiSchedPolicyChange(int index) if (consoleWindow->setSchedParam(policy, prio)) { - char msg[1024]; - - sprintf(msg, "Error: system call pthread_setschedparam Failed\nReason: %s\n", strerror(errno)); -#ifdef __linux__ - strcat(msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); - strcat(msg, " /etc/security/limits.conf \n\n"); - strcat(msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); - strcat(msg, "* - priority 99 \n"); - strcat(msg, "* - rtprio 99 \n"); - strcat(msg, "* - nice -20 \n"); -#endif - printf("%s\n", msg); - consoleWindow->QueueErrorMsgWindow(msg); + QString msg = getSchedPrioErrorMsg("pthread_setschedparam", errno); + printf("%s\n", msg.toLocal8Bit().constData()); + consoleWindow->QueueErrorMsgWindow(msg.toLocal8Bit().constData()); } updatePolicyBox(); diff --git a/src/drivers/Qt/TimingConf.h b/src/drivers/Qt/TimingConf.h index f644f1e0..ed1da26f 100644 --- a/src/drivers/Qt/TimingConf.h +++ b/src/drivers/Qt/TimingConf.h @@ -63,6 +63,7 @@ private: void updateTimingMech(void); void updateOverclocking(void); void saveValues(void); + QString getSchedPrioErrorMsg(const char* funcName, int errorCode); public slots: void closeWindow(void); diff --git a/src/drivers/Qt/TraceFileWriter.h b/src/drivers/Qt/TraceFileWriter.h new file mode 100644 index 00000000..df249d6c --- /dev/null +++ b/src/drivers/Qt/TraceFileWriter.h @@ -0,0 +1,470 @@ +#pragma once + +#include +#include +#include + +// High-performance class for writing a series of text lines to a file, using overlapped, unbuffered I/O +// Works on Windows builds both SDL/Qt and non-SQL/Qt +// Apart from getLastError, the entire API can be adapted to other OS with no client changes +class TraceFileWriter +{ +public: + static const size_t BlockSize = 4 << 10; + static const size_t BuffSize = BlockSize * 257; + static const size_t FlushSize = BlockSize * 256; + + inline TraceFileWriter() + { + // Windows Vista API that allows setting the end of file without closing and reopening it + HMODULE kernel32 = GetModuleHandleA("kernel32"); + SetFileInformationByHandle = kernel32 ? (SetFileInformationByHandlePtr)GetProcAddress(kernel32, "SetFileInformationByHandle") : nullptr; + + initialize(); + } + + inline ~TraceFileWriter() + { + if (isOpen) + close(); + } + + inline bool getOpen() const + { + return isOpen; + } + + // SUPPOSED to always be valid (ERROR_SUCCESS if no error), but bugs may make it only valid after a failure + inline DWORD getLastError() const + { + return lastErr; + } + + // Open the file and allocate all necessary resources + bool open(const char *fileName, bool isPaused = false) + { + HANDLE file = CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, nullptr); + if (file == INVALID_HANDLE_VALUE) + { + lastErr = GetLastError(); + return false; + } + + initialize(false, isPaused, fileName, file); + + // Allocate resources + do + { + for (unsigned i = 0; i < 2; i++) + { + buffers[i] = (char *)VirtualAlloc(NULL, BuffSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + if (buffers[i] == nullptr) + { + lastErr = GetLastError(); + break; + } + + ovls[i].hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); + if (ovls[i].hEvent == nullptr) + { + lastErr = GetLastError(); + break; + } + } + + if (!lastErr) + isOpen = true; + } while (false); + + if (!isOpen) + // Free resources on failure + cleanup(); + + return isOpen; + } + + // Close the file and free resources + void close() + { + if (!isOpen) + { + lastErr = ERROR_FILE_NOT_FOUND; + return; + } + + for (unsigned i = 0; i < 2; i++) + waitForBuffer(i); + + writeTail(); + + cleanup(); + } + + // When going from unpaused to paused, flush file and set end of file so it can be accessed externally + bool setPause(bool isPaused) + { + if (isPaused && !this->isPaused) + { + // Wait for any outstanding writes to complete + for (unsigned i = 0; i < 2; i++) + { + if (!waitForBuffer(i)) + return false; + } + + // Write out anything still in the buffer + if (!writeTail()) + return false; + } + + this->isPaused = isPaused; + lastErr = ERROR_SUCCESS; + + return true; + } + + // Add a line to the buffer and write it out when the buffer is filled + // Under most failure cirumstances the line is added to the buffer + bool writeLine(const char *line) + { + if (!isOpen) + { + lastErr = ERROR_FILE_NOT_FOUND; + return false; + } + + // Add to buffer + static const char eol[] = "\r\n"; + size_t eolSize = strlen(eol); + char *buff = buffers[buffIdx]; + size_t lineLen = strlen(line); + if (buffOffs + lineLen + eolSize > BuffSize) + { + // Buffer is full. This shouldn't ever happen. + lastErr = ERROR_INTERNAL_ERROR; + return false; + } + + memcpy(buff + buffOffs, line, lineLen); + memcpy(buff + buffOffs + lineLen, eol, eolSize); + buffOffs += lineLen + eolSize; + + // Check if the previous write is done, to detect it as early as possible + unsigned prevBuff = (buffIdx + 1) % 2; + if (!waitForBuffer(prevBuff, 0) && lastErr != ERROR_TIMEOUT) + return false; + + lastErr = ERROR_SUCCESS; + + if (buffOffs < FlushSize) + return true; + + return writeBlocks(); + } + + // Flush buffer contents. Writes partial blocks, but does NOT set end of file + // Do NOT call frequently, as writes may be significantly undersized and cause poor performance + bool flush() + { + if (!isOpen) + { + lastErr = ERROR_FILE_NOT_FOUND; + return false; + } + + // Write full blocks, if any + if (!writeBlocks()) + return false; + + char *buff = buffers[buffIdx]; + if (buffOffs != 0) + { + // Write out partial block at the tail + size_t writeSize = (buffOffs + BlockSize - 1) & ~(BlockSize - 1); + memset(buff + buffOffs, ' ', writeSize - buffOffs); + + if (!beginWrite(writeSize) + || !waitForBuffer(buffIdx)) + return false; + + // Do NOT update buffIdx, buffOffs, or fileOffs, as the partial block must be overwritten later + } + + // Wait for all writes to complete + for (unsigned i = 0; i < 2; i++) + { + if (!waitForBuffer(i)) + return false; + } + + lastErr = ERROR_SUCCESS; + return true; + } + +protected: + typedef BOOL (*SetFileInformationByHandlePtr)( + HANDLE hFile, + FILE_INFO_BY_HANDLE_CLASS FileInformationClass, + LPVOID lpFileInformation, + DWORD dwBufferSize + ); + + SetFileInformationByHandlePtr SetFileInformationByHandle; + + const size_t NO_WRITE = size_t(-1); + + DWORD lastErr; + + bool isOpen; + bool isPaused; + + std::string fileName; + HANDLE file; + + // Double-buffers + char *buffers[2]; + OVERLAPPED ovls[2]; + size_t bytesToWrite[2]; // Write in progress size or size_t(-1) if none + + unsigned buffIdx; + size_t buffOffs; + uint64_t fileOffs; + + // Put the class into a defined state, but does NOT allocate resources + void initialize(bool isOpen = false, bool isPaused = false, const char *fileName = "", HANDLE file = INVALID_HANDLE_VALUE) + { + lastErr = ERROR_SUCCESS; + + this->isOpen = isOpen; + this->isPaused = isPaused; + + this->fileName = fileName; + this->file = file; + + for (unsigned i = 0; i < 2; i++) + { + buffers[i] = nullptr; + bytesToWrite[i] = NO_WRITE; + } + + memset(ovls, 0, sizeof(ovls)); + + buffIdx = 0; + buffOffs = 0; + fileOffs = 0; + } + + // Close file and release resources. Does NOT wait for writes to complete. + void cleanup() + { + isOpen = false; + + if (file != INVALID_HANDLE_VALUE) + { + CloseHandle(file); + file = INVALID_HANDLE_VALUE; + } + + for (unsigned i = 0; i < 2; i++) + { + if (buffers[i] != nullptr) + VirtualFree(buffers[i], 0, MEM_RELEASE); + if (ovls[i].hEvent != nullptr) + CloseHandle(ovls[i].hEvent); + + buffers[i] = nullptr; + ovls[i].hEvent = nullptr; + } + } + + // Write out as many blocks as present in the buffer + bool writeBlocks() + { + if (buffOffs < BlockSize) + return true; + + char *buff = buffers[buffIdx]; + unsigned prevBuff = (buffIdx + 1) % 2; + OVERLAPPED *ovl = &ovls[buffIdx]; + + DWORD writeSize = buffOffs - (buffOffs % BlockSize); + if (!beginWrite(writeSize)) + return false; + + bool isAsync = bytesToWrite[buffIdx] != NO_WRITE; + if (isAsync) + { + if (!waitForBuffer(prevBuff)) + return false; // Catastrophic failure case + + // Switch to next buffer + + memcpy(buffers[prevBuff], buff + writeSize, buffOffs - writeSize); + buffOffs -= writeSize; + + fileOffs += writeSize; + + buffIdx = prevBuff; + } + else + { + // Stick with same buffer + memmove(buff, buff + writeSize, buffOffs - writeSize); + + buffOffs -= writeSize; + } + + bytesToWrite[buffIdx] = NO_WRITE; + + return true; + } + + // Begin a write and handle errors without updating class state + bool beginWrite(size_t writeSize) + { + bytesToWrite[buffIdx] = NO_WRITE; + + if (writeSize % BlockSize != 0) + { + lastErr = ERROR_INTERNAL_ERROR; + return false; + } + + OVERLAPPED *ovl = &ovls[buffIdx]; + ovl->Offset = (DWORD)fileOffs; + ovl->OffsetHigh = DWORD(fileOffs >> 32); + + bool success = false; + DWORD bytesWritten; + if (WriteFile(file, buffers[buffIdx], writeSize, &bytesWritten, ovl)) + { + // Completed synchronously + lastErr = (bytesWritten == writeSize) + ? ERROR_SUCCESS + : ERROR_WRITE_FAULT; // "Close enough" + } + else + { + DWORD lastErr = GetLastError(); + if (lastErr == ERROR_IO_PENDING) + { + bytesToWrite[buffIdx] = writeSize; + lastErr = ERROR_SUCCESS; + } + } + + return !lastErr; + } + + // Set the end of file so it can be accessed + bool setEndOfFile() + { + if (SetFileInformationByHandle != nullptr) + { + // Easy case: Vista or better + FILE_END_OF_FILE_INFO eofInfo; + eofInfo.EndOfFile.QuadPart = int64_t(fileOffs + buffOffs); + + if (!SetFileInformationByHandle(file, FileEndOfFileInfo, &eofInfo, sizeof(eofInfo))) + { + lastErr = GetLastError(); + return false; + } + + lastErr = ERROR_SUCCESS; + return true; + } + else + { + // Hard case: XP + // If set EOF fails, make a desperate attempt to reopen the file and keep running + lastErr = ERROR_SUCCESS; + do + { + // Set EOF to fileOffs rounded up to the next block + LARGE_INTEGER tgtOffs; + tgtOffs.QuadPart = (fileOffs + buffOffs + BlockSize - 1) & ~(BlockSize - 1); + LARGE_INTEGER newOffs; + + if (!SetFilePointerEx(file, tgtOffs, &newOffs, FILE_BEGIN) + || !SetEndOfFile(file)) + break; + + CloseHandle(file); + + // Open file with buffering so the exact byte size can be set + tgtOffs.QuadPart = fileOffs + buffOffs; + + file = CreateFile(fileName.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); + if (file != INVALID_HANDLE_VALUE) + { + if (!SetFilePointerEx(file, tgtOffs, &newOffs, FILE_BEGIN) + || !SetEndOfFile(file)) + lastErr = GetLastError(); + + CloseHandle(file); + } + else + lastErr = GetLastError(); + + // Finally, reopen the file in original mode + file = CreateFile(fileName.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, + FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, nullptr); + if (file == INVALID_HANDLE_VALUE || lastErr) + break; + + lastErr = ERROR_SUCCESS; + return true; + } while (false); + + // Failed + if (!lastErr) + lastErr = GetLastError(); + + return false; + } + } + + // Write out everything in the buffer and set the file end for pausing + inline bool writeTail() + { + return flush() && setEndOfFile(); + } + + // Wait for an a buffer to become available, waiting for write completion if necessary + bool waitForBuffer(unsigned buffIdx, DWORD timeout = INFINITE) + { + if (buffIdx >= 2) + lastErr = ERROR_INTERNAL_ERROR; + else if (bytesToWrite[buffIdx] == NO_WRITE) + // No write in progress + lastErr = ERROR_SUCCESS; + else + { + // Wait for the operation to complete + DWORD waitRes = WaitForSingleObject(ovls[buffIdx].hEvent, timeout); + if (waitRes == WAIT_TIMEOUT) + lastErr = ERROR_TIMEOUT; + else if (waitRes != WAIT_OBJECT_0) + { + lastErr = GetLastError(); + bytesToWrite[buffIdx] = NO_WRITE; + } + else + { + // Verify it succeeded + DWORD prevBytesWritten; + if (!GetOverlappedResult(file, &ovls[buffIdx], &prevBytesWritten, FALSE)) + lastErr = GetLastError(); + else if (prevBytesWritten != bytesToWrite[buffIdx]) + lastErr = ERROR_WRITE_FAULT; + else + lastErr = ERROR_SUCCESS; + + bytesToWrite[buffIdx] = NO_WRITE; + } + } + + return !lastErr; + } +}; diff --git a/src/drivers/Qt/TraceLogger.cpp b/src/drivers/Qt/TraceLogger.cpp index 5dff5fbf..6eabb3c4 100644 --- a/src/drivers/Qt/TraceLogger.cpp +++ b/src/drivers/Qt/TraceLogger.cpp @@ -25,6 +25,7 @@ #ifdef WIN32 #include +#include #else #include #include @@ -56,6 +57,7 @@ #include "../../movie.h" #include "common/os_utils.h" +#include "utils/StringBuilder.h" #include "Qt/ConsoleDebugger.h" #include "Qt/ConsoleWindow.h" @@ -914,38 +916,17 @@ traceRecord_t::traceRecord_t(void) //---------------------------------------------------- int traceRecord_t::appendAsmText(const char *txt) { - int i = 0; + size_t len = strlen(txt); + memcpy(asmTxt + asmTxtSize, txt, len + 1); - while (txt[i] != 0) - { - asmTxt[asmTxtSize] = txt[i]; - i++; - asmTxtSize++; - } - asmTxt[asmTxtSize] = 0; + asmTxtSize += len; return 0; } //---------------------------------------------------- -static int convToXchar(int i) -{ - int c = 0; - - if ((i >= 0) && (i < 10)) - { - c = i + '0'; - } - else if (i < 16) - { - c = (i - 10) + 'A'; - } - return c; -} -//---------------------------------------------------- int traceRecord_t::convToText(char *txt, int *len) { int i = 0, j = 0; - char stmp[128]; char str_axystate[32], str_procstatus[32]; str_axystate[0] = 0; @@ -954,112 +935,56 @@ int traceRecord_t::convToText(char *txt, int *len) txt[0] = 0; if (opSize == 0) { - j = 0; - while (asmTxt[j] != 0) - { - txt[i] = asmTxt[j]; - i++; - j++; - } - txt[i] = 0; + strcpy(txt, asmTxt); return -1; } + StringBuilder sb(txt + i); if (skippedLines > 0) - { - sprintf(stmp, "(%d lines skipped) ", skippedLines); - - j = 0; - while (stmp[j] != 0) - { - txt[i] = stmp[j]; - i++; - j++; - } - } + sb << '(' << sb_dec(skippedLines) << " lines skipped) "; // Start filling the str_temp line: Frame count, Cycles count, Instructions count, AXYS state, Processor status, Tabs, Address, Data, Disassembly if (logging_options & LOG_FRAMES_COUNT) - { - sprintf(stmp, "f%-6llu ", (long long unsigned int)frameCount); - - j = 0; - while (stmp[j] != 0) - { - txt[i] = stmp[j]; - i++; - j++; - } - } + sb << 'f' << sb_dec(frameCount, -6); if (logging_options & LOG_CYCLES_COUNT) - { - sprintf(stmp, "c%-11llu ", (long long unsigned int)cycleCount); - - j = 0; - while (stmp[j] != 0) - { - txt[i] = stmp[j]; - i++; - j++; - } - } + sb << 'c' << sb_dec(cycleCount, -11); if (logging_options & LOG_INSTRUCTIONS_COUNT) - { - sprintf(stmp, "i%-11llu ", (long long unsigned int)instrCount); - - j = 0; - while (stmp[j] != 0) - { - txt[i] = stmp[j]; - i++; - j++; - } - } + sb << 'i' << sb_dec(instrCount, -11); if (logging_options & LOG_REGISTERS) { - sprintf(str_axystate, "A:%02X X:%02X Y:%02X S:%02X ", (cpu.A), (cpu.X), (cpu.Y), (cpu.S)); + StringBuilder sb(str_axystate); + sb << "A:" << sb_hex(cpu.A, 2) + << " X:" << sb_hex(cpu.X, 2) + << " Y:" << sb_hex(cpu.Y, 2) + << " S:" << sb_hex(cpu.S, 2) + << ' '; } if (logging_options & LOG_PROCESSOR_STATUS) { - int tmp = cpu.P ^ 0xFF; - sprintf(str_procstatus, "P:%c%c%c%c%c%c%c%c ", - 'N' | (tmp & 0x80) >> 2, - 'V' | (tmp & 0x40) >> 1, - 'U' | (tmp & 0x20), - 'B' | (tmp & 0x10) << 1, - 'D' | (tmp & 0x08) << 2, - 'I' | (tmp & 0x04) << 3, - 'Z' | (tmp & 0x02) << 4, - 'C' | (tmp & 0x01) << 5); + char *s = str_procstatus; + *(s++) = cpu.P & 0x80 ? 'N' : 'n'; + *(s++) = cpu.P & 0x40 ? 'V' : 'v'; + *(s++) = cpu.P & 0x20 ? 'U' : 'u'; + *(s++) = cpu.P & 0x10 ? 'B' : 'b'; + *(s++) = cpu.P & 0x08 ? 'D' : 'd'; + *(s++) = cpu.P & 0x04 ? 'I' : 'i'; + *(s++) = cpu.P & 0x02 ? 'Z' : 'z'; + *(s++) = cpu.P & 0x01 ? 'C' : 'c'; + *(s++) = ' '; + *(s++) = '\0'; } if (logging_options & LOG_TO_THE_LEFT) { if (logging_options & LOG_REGISTERS) - { - j = 0; - while (str_axystate[j] != 0) - { - txt[i] = str_axystate[j]; - i++; - j++; - } - } + sb << str_axystate; if (logging_options & LOG_PROCESSOR_STATUS) - { - j = 0; - while (str_procstatus[j] != 0) - { - txt[i] = str_procstatus[j]; - i++; - j++; - } - } + sb << str_procstatus; } if (logging_options & LOG_CODE_TABBING) @@ -1067,106 +992,44 @@ int traceRecord_t::convToText(char *txt, int *len) // add spaces at the beginning of the line according to stack pointer int spaces = (0xFF - cpu.S) & LOG_TABS_MASK; - while (spaces > 0) - { - txt[i] = ' '; - i++; - spaces--; - } + for (; spaces > 0; spaces--) + sb << ' '; } else if (logging_options & LOG_TO_THE_LEFT) - { - txt[i] = ' '; - i++; - } + sb << ' '; if (logging_options & LOG_BANK_NUMBER) { if (cpu.PC >= 0x8000) - { - sprintf(stmp, "$%02X:%04X: ", bank, cpu.PC); - } + sb << sb_addr((uint8_t)bank, 2) << ':'; else - { - sprintf(stmp, " $%04X: ", cpu.PC); - } + sb << " $"; } else - { - sprintf(stmp, "$%04X: ", cpu.PC); - } - j = 0; - while (stmp[j] != 0) - { - txt[i] = stmp[j]; - i++; - j++; - } + sb << '$'; + + sb << sb_hex(cpu.PC, 4) << ": "; for (j = 0; j < opSize; j++) - { - txt[i] = convToXchar((opCode[j] >> 4) & 0x0F); - i++; - txt[i] = convToXchar(opCode[j] & 0x0F); - i++; - txt[i] = ' '; - i++; - } - while (j < 3) - { - txt[i] = ' '; - i++; - txt[i] = ' '; - i++; - txt[i] = ' '; - i++; - j++; - } - j = 0; - while (asmTxt[j] != 0) - { - txt[i] = asmTxt[j]; - i++; - j++; - } - if (callAddr >= 0) - { - sprintf(stmp, " (from $%04X)", callAddr); + sb << sb_hex(opCode[j], 2) << ' '; + for (; j < 3; j++) + sb << " "; - j = 0; - while (stmp[j] != 0) - { - txt[i] = stmp[j]; - i++; - j++; - } - } + sb << asmTxt; + + if (callAddr >= 0) + sb << " (from " << sb_addr((uint16_t)callAddr) << ')'; if (!(logging_options & LOG_TO_THE_LEFT)) { if (logging_options & LOG_REGISTERS) - { - j = 0; - while (str_axystate[j] != 0) - { - txt[i] = str_axystate[j]; - i++; - j++; - } - } + sb << str_axystate; if (logging_options & LOG_PROCESSOR_STATUS) - { - j = 0; - while (str_procstatus[j] != 0) - { - txt[i] = str_procstatus[j]; - i++; - j++; - } - } + sb << str_procstatus; } - txt[i] = 0; + i = int(sb.str() + sb.size() - txt); + txt[i] = '\0'; if (len) { @@ -1249,12 +1112,15 @@ static void pushToLogBuffer(traceRecord_t &rec) break; } } + + bool overrun = nextHead == logBufTail; + logBufHead = nextHead; if ( overrunWarningArmed ) { // Don't spam with buffer overrun warning messages, // we will print once if this happens. - if (logBufHead == logBufTail) + if (overrun) { if ( traceLogWindow ) { @@ -1378,7 +1244,7 @@ void FCEUD_TraceInstruction(uint8 *opcode, int size) olddatacount = datacount; if (unloggedlines > 0) { - //sprintf(str_result, "(%d lines skipped)", unloggedlines); + //snprintf(str_result, "(%d lines skipped)", unloggedlines); rec.skippedLines = unloggedlines; unloggedlines = 0; } @@ -1399,8 +1265,8 @@ void FCEUD_TraceInstruction(uint8 *opcode, int size) if ((addr + size) > 0xFFFF) { - //sprintf(str_data, "%02X ", opcode[0]); - //sprintf(str_disassembly, "OVERFLOW"); + //snprintf(str_data, "%02X ", opcode[0]); + //snprintf(str_disassembly, "OVERFLOW"); rec.flags |= 0x01; } else @@ -1409,7 +1275,7 @@ void FCEUD_TraceInstruction(uint8 *opcode, int size) switch (size) { case 0: - //sprintf(str_disassembly,"UNDEFINED"); + //snprintf(str_disassembly,"UNDEFINED"); rec.flags |= 0x02; break; case 1: @@ -2046,13 +1912,13 @@ void QTraceLogView::openBpEditWindow(int editIdx, watchpointinfo *wp, traceRecor sprite_radio->setChecked(true); } - sprintf(stmp, "%04X", wp->address); + snprintf(stmp, sizeof(stmp), "%04X", wp->address); addr1->setText(tr(stmp)); if (wp->endaddress > 0) { - sprintf(stmp, "%04X", wp->endaddress); + snprintf(stmp, sizeof(stmp), "%04X", wp->endaddress); addr2->setText(tr(stmp)); } @@ -2092,11 +1958,11 @@ void QTraceLogView::openBpEditWindow(int editIdx, watchpointinfo *wp, traceRecor char str[64]; if ((wp->address == recp->cpu.PC) && (recp->bank >= 0)) { - sprintf(str, "K==#%02X", recp->bank); + snprintf(str, sizeof(str), "K==#%02X", recp->bank); } else { - sprintf(str, "K==#%02X", getBank(wp->address)); + snprintf(str, sizeof(str), "K==#%02X", getBank(wp->address)); } cond->setText(tr(str)); } @@ -2536,9 +2402,7 @@ TraceLogDiskThread_t::~TraceLogDiskThread_t(void) void TraceLogDiskThread_t::run(void) { char line[256]; - char buf[8192]; - int i,idx=0; - int blockSize = 4 * 1024; + const unsigned blockSize = 4 * 1024; bool dataNeedsFlush = true; bool isPaused = false; @@ -2547,24 +2411,27 @@ void TraceLogDiskThread_t::run(void) setPriority( QThread::HighestPriority ); #ifdef WIN32 - logFile = CreateFileA( logFilePath.c_str(), GENERIC_WRITE, - 0, NULL, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL ); - - if ( logFile == INVALID_HANDLE_VALUE ) + TraceFileWriter tracer; + if (!tracer.open(logFilePath.c_str(), (bool)FCEUI_EmulationPaused())) { char stmp[1024]; - sprintf( stmp, "Error: Failed to open log file for writing: %s", logFilePath.c_str() ); + snprintf( stmp, sizeof(stmp), "Error: Failed to open log file for writing: %s", logFilePath.c_str() ); consoleWindow->QueueErrorMsgWindow(stmp); return; } #else + const unsigned bufSize = blockSize * 2; + const unsigned flushSize = blockSize; + char buf[bufSize]; + unsigned int i, idx=0; + logFile = open( logFilePath.c_str(), O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH ); if ( logFile == -1 ) { char stmp[1024]; - sprintf( stmp, "Error: Failed to open log file for writing: %s", logFilePath.c_str() ); + snprintf( stmp, sizeof(stmp), "Error: Failed to open log file for writing: %s", logFilePath.c_str() ); consoleWindow->QueueErrorMsgWindow(stmp); return; } @@ -2579,7 +2446,6 @@ void TraceLogDiskThread_t::run(void) logBuf = (traceRecord_t *)malloc(size); } - idx = 0; while ( !isInterruptionRequested() ) { @@ -2588,7 +2454,13 @@ void TraceLogDiskThread_t::run(void) while (logBufHead != logBufTail) { logBuf[logBufTail].convToText(line); + logBufTail = (logBufTail + 1) % logBufMax; + #ifdef WIN32 + bool success = tracer.writeLine(line); + + /// TODO: Do something on error + #else i=0; while ( line[i] != 0 ) { @@ -2596,24 +2468,23 @@ void TraceLogDiskThread_t::run(void) } buf[idx] = '\n'; idx++; - logBufTail = (logBufTail + 1) % logBufMax; - - if ( idx >= blockSize ) + if ( idx >= flushSize ) { - #ifdef WIN32 - DWORD bytesWritten; - WriteFile( logFile, buf, idx, &bytesWritten, NULL ); idx = 0; - #else if ( write( logFile, buf, idx ) < 0 ) { // HANDLE ERROR TODO } idx = 0; - #endif dataNeedsFlush = true; } + #endif } + #ifdef WIN32 + bool success = tracer.setPause(isPaused); + + /// TODO: Do something on error + #else if (isPaused) { // If paused, the user might be at a breakpoint or doing some @@ -2621,55 +2492,40 @@ void TraceLogDiskThread_t::run(void) // Only flush data when paused, to keep write efficiency up. if ( idx > 0 ) { - #ifdef WIN32 - DWORD bytesWritten; - WriteFile( logFile, buf, idx, &bytesWritten, NULL ); idx = 0; - #else if ( write( logFile, buf, idx ) < 0 ) { // HANDLE ERROR TODO } idx = 0; - #endif dataNeedsFlush = true; } if (dataNeedsFlush) { //printf("Flushing Trace Log Disk Buffers\n"); - #ifdef WIN32 - FlushFileBuffers( logFile ); - #else if ( fsync( logFile ) ) { printf("Trace Log fsync error\n"); } - #endif dataNeedsFlush = false; } } + #endif + SDL_Delay(1); } + #ifdef WIN32 + tracer.close(); + #else if ( idx > 0 ) { - #ifdef WIN32 - DWORD bytesWritten; - WriteFile( logFile, buf, idx, &bytesWritten, NULL ); idx = 0; - #else if ( write( logFile, buf, idx ) < 0 ) { // HANDLE ERROR TODO } idx = 0; - #endif } - #ifdef WIN32 - if ( logFile != INVALID_HANDLE_VALUE ) - { - CloseHandle( logFile ); logFile = INVALID_HANDLE_VALUE; - } - #else if ( logFile != -1 ) { close(logFile); logFile = -1; diff --git a/src/drivers/Qt/config.cpp b/src/drivers/Qt/config.cpp index 3d0ae813..e31cf378 100644 --- a/src/drivers/Qt/config.cpp +++ b/src/drivers/Qt/config.cpp @@ -817,7 +817,7 @@ InitConfig() for (unsigned int i=0; i<10; i++) { char buf[128]; - sprintf(buf, "SDL.RecentRom%02u", i); + snprintf(buf, sizeof(buf), "SDL.RecentRom%02u", i); config->addOption( buf, ""); } @@ -825,7 +825,7 @@ InitConfig() for (unsigned int i=0; i<10; i++) { char buf[128]; - sprintf(buf, "SDL.RecentTasProject%02u", i); + snprintf(buf, sizeof(buf), "SDL.RecentTasProject%02u", i); config->addOption( buf, ""); } @@ -1084,7 +1084,7 @@ InitConfig() //keyText.assign(" mod="); - //sprintf( buf, " key=%s", SDL_GetKeyName( Hotkeys[i] ) ); + //snprintf( buf, sizeof(buf), " key=%s", SDL_GetKeyName( Hotkeys[i] ) ); if ( hotKeyName[0] != 0 ) { diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index aef58cca..84730e3c 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -1371,7 +1371,7 @@ void fceuWrapperLock(const char *filename, int line, const char *func) printf("Already Locked By: %s\n", lockFile.c_str() ); printf("Requested By: %s:%i - %s\n", filename, line, func ); } - sprintf( txt, ":%i - ", line ); + snprintf( txt, sizeof(txt), ":%i - ", line ); lockFile.assign(filename); lockFile.append(txt); lockFile.append(func); @@ -1398,7 +1398,7 @@ bool fceuWrapperTryLock(const char *filename, int line, const char *func, int ti if ( lockAcq && debugMutexLock) { char txt[32]; - sprintf( txt, ":%i - ", line ); + snprintf( txt, sizeof(txt), ":%i - ", line ); lockFile.assign(filename); lockFile.append(txt); lockFile.append(func); diff --git a/src/drivers/Qt/iNesHeaderEditor.cpp b/src/drivers/Qt/iNesHeaderEditor.cpp index 2d78946e..63808f84 100644 --- a/src/drivers/Qt/iNesHeaderEditor.cpp +++ b/src/drivers/Qt/iNesHeaderEditor.cpp @@ -238,7 +238,7 @@ iNesHeaderEditor_t::iNesHeaderEditor_t(QWidget *parent) for (i = 0; bmap[i].init; ++i) { - sprintf(stmp, "%d %s", bmap[i].number, bmap[i].name); + snprintf(stmp, sizeof(stmp), "%d %s", bmap[i].number, bmap[i].name); mapperComboBox->addItem( tr(stmp), bmap[i].number ); } @@ -307,25 +307,25 @@ iNesHeaderEditor_t::iNesHeaderEditor_t(QWidget *parent) if (size >= 1024 << 3) { // The size of CHR ROM must be multiple of 8KB - sprintf( stmp, "%d KB", size / 1024); + snprintf( stmp, sizeof(stmp), "%d KB", size / 1024); chrRomBox->addItem( tr(stmp), size ); // The size of PRG ROM must be multiple of 16KB if (size >= 1024 * 16) { // PRG ROM - sprintf(stmp, "%d KB", size / 1024); + snprintf(stmp, sizeof(stmp), "%d KB", size / 1024); prgRomBox->addItem( tr(stmp), size ); } } if (size >= 1024) { - sprintf( stmp, "%d KB", size / 1024); + snprintf( stmp, sizeof(stmp), "%d KB", size / 1024); } else { - sprintf( stmp, "%d B", size); + snprintf( stmp, sizeof(stmp), "%d B", size); } prgRamBox->addItem( tr(stmp), size ); @@ -911,7 +911,7 @@ void iNesHeaderEditor_t::setHeaderData(iNES_HEADER* header) { if ( mapperComboBox->itemData(i).toInt() > mapper ) { - sprintf( buf, "%i Unknown/unsupported", i); + snprintf( buf, sizeof(buf), "%i Unknown/unsupported", i); mapperComboBox->insertItem( i, tr(buf), mapper); mapperComboBox->setCurrentIndex(i); break; @@ -924,7 +924,7 @@ void iNesHeaderEditor_t::setHeaderData(iNES_HEADER* header) } // Sub Mapper - sprintf(buf, "%d", ines20 ? header->ROM_type3 >> 4 : 0); + snprintf(buf, sizeof(buf), "%d", ines20 ? header->ROM_type3 >> 4 : 0); mapperSubEdit->setText( tr(buf) ); @@ -1210,7 +1210,7 @@ void iNesHeaderEditor_t::setHeaderData(iNES_HEADER* header) } // Miscellaneous ROM Area(s) - sprintf(buf, "%d", header->misc_roms & 3); + snprintf(buf, sizeof(buf), "%d", header->misc_roms & 3); miscRomsEdit->setText( tr(buf) ); // Trainer @@ -1398,7 +1398,7 @@ bool iNesHeaderEditor_t::WriteHeaderData(iNES_HEADER* header) } else { - sprintf(buf, "Error: Mapper# should be less than %d in iNES %d.0 format.", 256, 1); + snprintf(buf, sizeof(buf), "Error: Mapper# should be less than %d in iNES %d.0 format.", 256, 1); showErrorMsgWindow(buf); return false; } @@ -1406,7 +1406,7 @@ bool iNesHeaderEditor_t::WriteHeaderData(iNES_HEADER* header) } else { - sprintf(buf, "Mapper# should be less than %d in iNES %d.0 format.", 4096, 2); + snprintf(buf, sizeof(buf), "Mapper# should be less than %d in iNES %d.0 format.", 4096, 2); showErrorMsgWindow(buf); return false; } @@ -1483,13 +1483,13 @@ bool iNesHeaderEditor_t::WriteHeaderData(iNES_HEADER* header) char buf2[64]; if (result % 1024 != 0) { - sprintf(buf2, "%dB", result); + snprintf(buf2, sizeof(buf2), "%dB", result); } else { - sprintf(buf2, "%dKB", result / 1024); + snprintf(buf2, sizeof(buf2), "%dKB", result / 1024); } - sprintf(buf, "PRG ROM size you entered is invalid in iNES 2.0, do you want to set to its nearest value %s?", buf2); + snprintf(buf, sizeof(buf), "PRG ROM size you entered is invalid in iNES 2.0, do you want to set to its nearest value %s?", buf2); showErrorMsgWindow(buf); //if (MessageBox(hwnd, buf, "Error", MB_YESNO | MB_ICONERROR) == IDYES) //{ @@ -1691,13 +1691,13 @@ bool iNesHeaderEditor_t::WriteHeaderData(iNES_HEADER* header) char buf2[64]; if (result % 1024 != 0) { - sprintf(buf2, "%dB", result); + snprintf(buf2, sizeof(buf2), "%dB", result); } else { - sprintf(buf2, "%dKB", result / 1024); + snprintf(buf2, sizeof(buf2), "%dKB", result / 1024); } - sprintf(buf, "CHR ROM size you entered is invalid in iNES 2.0, do you want to set to its nearest value %s?", buf2); + snprintf(buf, sizeof(buf), "CHR ROM size you entered is invalid in iNES 2.0, do you want to set to its nearest value %s?", buf2); showErrorMsgWindow(buf); //if (MessageBox(hwnd, buf, "Error", MB_YESNO | MB_ICONERROR) == IDYES) // SetDlgItemText(hwnd, IDC_CHRROM_COMBO, buf2); @@ -1986,7 +1986,7 @@ bool iNesHeaderEditor_t::WriteHeaderData(iNES_HEADER* header) int ret; QMessageBox msgBox(this); - sprintf(buf, "FCEUX doesn't support iNES Mapper# %d, this is not a serious problem, but the ROM will not be run in FCEUX properly.\nDo you want to continue?", mapper); + snprintf(buf, sizeof(buf), "FCEUX doesn't support iNES Mapper# %d, this is not a serious problem, but the ROM will not be run in FCEUX properly.\nDo you want to continue?", mapper); msgBox.setIcon( QMessageBox::Warning ); msgBox.setText( tr(buf) ); diff --git a/src/drivers/Qt/input.cpp b/src/drivers/Qt/input.cpp index 57ce9bd4..366fb52a 100644 --- a/src/drivers/Qt/input.cpp +++ b/src/drivers/Qt/input.cpp @@ -2138,7 +2138,7 @@ const char *ButtonName(const ButtConfig *bc) inputNum = bc->ButtonNum; inputDirection = ""; } - sprintf(name, "js%i:%s%i%s", joyNum, inputType, inputNum, inputDirection); + snprintf(name, sizeof(name), "js%i:%s%i%s", joyNum, inputType, inputNum, inputDirection); } break; } diff --git a/src/drivers/Qt/ppuViewer.cpp b/src/drivers/Qt/ppuViewer.cpp index f043fcca..f2c18478 100644 --- a/src/drivers/Qt/ppuViewer.cpp +++ b/src/drivers/Qt/ppuViewer.cpp @@ -887,7 +887,7 @@ void ppuPatternView_t::updateSelTileLabel(void) char stmp[32]; if ( (selTile.y() >= 0) && (selTile.x() >= 0) ) { - sprintf( stmp, "Tile: $%X%X", selTile.y(), selTile.x() ); + snprintf( stmp, sizeof(stmp), "Tile: $%X%X", selTile.y(), selTile.x() ); } else { @@ -949,7 +949,7 @@ void ppuPatternView_t::contextMenuEvent(QContextMenuEvent *event) if ( mode ) { - sprintf( stmp, "Exit Tile &View: %X%X", selTile.y(), selTile.x() ); + snprintf( stmp, sizeof(stmp), "Exit Tile &View: %X%X", selTile.y(), selTile.x() ); act = new QAction(tr(stmp), &menu); act->setShortcut( QKeySequence(tr("Z"))); @@ -958,7 +958,7 @@ void ppuPatternView_t::contextMenuEvent(QContextMenuEvent *event) } else { - sprintf( stmp, "&View Tile: %X%X", selTile.y(), selTile.x() ); + snprintf( stmp, sizeof(stmp), "&View Tile: %X%X", selTile.y(), selTile.x() ); act = new QAction(tr(stmp), &menu); act->setShortcut( QKeySequence(tr("Z"))); @@ -987,7 +987,7 @@ void ppuPatternView_t::contextMenuEvent(QContextMenuEvent *event) { char stmp[8]; - sprintf( stmp, "&%i", i+1 ); + snprintf( stmp, sizeof(stmp), "&%i", i+1 ); paletteAct[i] = new QAction(tr(stmp), &menu); paletteAct[i]->setCheckable(true); @@ -1787,13 +1787,13 @@ void tilePaletteView_t::contextMenuEvent(QContextMenuEvent *event) subMenu = menu.addMenu( tr("Copy Color to Clipboard") ); - sprintf( stmp, "Hex #%02X%02X%02X", palo[i].r, palo[i].g, palo[i].b ); + snprintf( stmp, sizeof(stmp), "Hex #%02X%02X%02X", palo[i].r, palo[i].g, palo[i].b ); act = new QAction(tr(stmp), &menu); //act->setShortcut( QKeySequence(tr("G"))); connect( act, SIGNAL(triggered(void)), this, SLOT(copyColor2ClipBoardHex(void)) ); subMenu->addAction( act ); - sprintf( stmp, "rgb(%3i,%3i,%3i)", palo[i].r, palo[i].g, palo[i].b ); + snprintf( stmp, sizeof(stmp), "rgb(%3i,%3i,%3i)", palo[i].r, palo[i].g, palo[i].b ); act = new QAction(tr(stmp), &menu); //act->setShortcut( QKeySequence(tr("G"))); connect( act, SIGNAL(triggered(void)), this, SLOT(copyColor2ClipBoardRGB(void)) ); @@ -1815,7 +1815,7 @@ void tilePaletteView_t::copyColor2ClipBoardHex(void) } p = palcache[ (palIdx << 2) | selBox ]; - sprintf( txt, "#%02X%02X%02X", palo[p].r, palo[p].g, palo[p].b ); + snprintf( txt, sizeof(txt), "#%02X%02X%02X", palo[p].r, palo[p].g, palo[p].b ); clipboard->setText( tr(txt), QClipboard::Clipboard ); @@ -1837,7 +1837,7 @@ void tilePaletteView_t::copyColor2ClipBoardRGB(void) } p = palcache[ (palIdx << 2) | selBox ]; - sprintf( txt, "rgb(%3i,%3i,%3i)", palo[p].r, palo[p].g, palo[p].b ); + snprintf( txt, sizeof(txt), "rgb(%3i,%3i,%3i)", palo[p].r, palo[p].g, palo[p].b ); clipboard->setText( tr(txt), QClipboard::Clipboard ); @@ -2164,7 +2164,7 @@ void ppuTileEditor_t::setTile( QPoint *t ) addr = addr + ( t->y() * 0x0100 ); addr = addr + ( t->x() * 0x0010 ); - sprintf( stmp, "Tile Index: $%X%X Address: $%04X", t->y(), t->x(), addr ); + snprintf( stmp, sizeof(stmp), "Tile Index: $%X%X Address: $%04X", t->y(), t->x(), addr ); tileIdxLbl->setText( tr(stmp) ); tileView->setTile( t ); @@ -2490,7 +2490,7 @@ void ppuTileView_t::contextMenuEvent(QContextMenuEvent *event) // // if ( mode ) // { -// sprintf( stmp, "Exit Tile View: %X%X", selTile.y(), selTile.x() ); +// snprintf( stmp, sizeof(stmp), "Exit Tile View: %X%X", selTile.y(), selTile.x() ); // // act = new QAction(tr(stmp), &menu); // act->setShortcut( QKeySequence(tr("Z"))); @@ -2506,7 +2506,7 @@ void ppuTileView_t::contextMenuEvent(QContextMenuEvent *event) // } // else // { -// sprintf( stmp, "View Tile: %X%X", selTile.y(), selTile.x() ); +// snprintf( stmp, sizeof(stmp), "View Tile: %X%X", selTile.y(), selTile.x() ); // // act = new QAction(tr(stmp), &menu); // act->setShortcut( QKeySequence(tr("Z"))); @@ -2533,7 +2533,7 @@ void ppuTileView_t::contextMenuEvent(QContextMenuEvent *event) // { // char stmp[8]; // -// sprintf( stmp, "%i", i+1 ); +// snprintf( stmp, sizeof(stmp), "%i", i+1 ); // // paletteAct[i] = new QAction(tr(stmp), &menu); // paletteAct[i]->setCheckable(true); @@ -2728,7 +2728,7 @@ void ppuTileEditColorPicker_t::mouseMoveEvent(QMouseEvent *event) // char stmp[64]; // int ix = (tile.y()<<4)|tile.x(); - // sprintf( stmp, "Palette: $%02X", palcache[ix]); + // snprintf( stmp, sizeof(stmp), "Palette: $%02X", palcache[ix]); // frame->setTitle( tr(stmp) ); //} @@ -3192,25 +3192,25 @@ void spriteViewerDialog_t::periodicUpdate(void) idx = oamView->getSpriteIndex(); - sprintf( stmp, "$%02X", idx ); + snprintf( stmp, sizeof(stmp), "$%02X", idx ); spriteIndexBox->setText( tr(stmp) ); - sprintf( stmp, "$%02X", oamPattern.sprite[idx].tNum ); + snprintf( stmp, sizeof(stmp), "$%02X", oamPattern.sprite[idx].tNum ); tileIndexBox->setText( tr(stmp) ); - sprintf( stmp, "$%04X", oamPattern.sprite[idx].chrAddr ); + snprintf( stmp, sizeof(stmp), "$%04X", oamPattern.sprite[idx].chrAddr ); tileAddrBox->setText( tr(stmp) ); - sprintf( stmp, "$%04X", 0x3F00 + (oamPattern.sprite[idx].pal*4) ); + snprintf( stmp, sizeof(stmp), "$%04X", 0x3F00 + (oamPattern.sprite[idx].pal*4) ); palAddrBox->setText( tr(stmp) ); if ( showPosHex->isChecked() ) { - sprintf( stmp, "$%02X, $%02X", oamPattern.sprite[idx].x, oamPattern.sprite[idx].y ); + snprintf( stmp, sizeof(stmp), "$%02X, $%02X", oamPattern.sprite[idx].x, oamPattern.sprite[idx].y ); } else { - sprintf( stmp, "%3i, %3i", oamPattern.sprite[idx].x, oamPattern.sprite[idx].y ); + snprintf( stmp, sizeof(stmp), "%3i, %3i", oamPattern.sprite[idx].x, oamPattern.sprite[idx].y ); } posBox->setText( tr(stmp) ); diff --git a/src/drivers/Qt/sdl-joystick.cpp b/src/drivers/Qt/sdl-joystick.cpp index 29f6b28c..5445fd9a 100644 --- a/src/drivers/Qt/sdl-joystick.cpp +++ b/src/drivers/Qt/sdl-joystick.cpp @@ -946,7 +946,7 @@ int GamePad_t::saveCurrentMapToFile(const char *name) output.append(name); output.append(","); output.append("config:"); - sprintf( stmp, "%i,", c ); + snprintf( stmp, sizeof(stmp), "%i,", c ); output.append(stmp); for (i = 0; i < GAMEPAD_NUM_BUTTONS; i++) @@ -970,26 +970,26 @@ int GamePad_t::saveCurrentMapToFile(const char *name) } stmp[k] = 0; - //sprintf(stmp, "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum)); + //snprintf(stmp, sizeof(stmp), "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum)); } else { if (bmap[c][i].ButtonNum & 0x2000) { /* Hat "button" */ - sprintf(stmp, "h%i.%i", + snprintf(stmp, sizeof(stmp), "h%i.%i", (bmap[c][i].ButtonNum >> 8) & 0x1F, bmap[c][i].ButtonNum & 0xFF); } else if (bmap[c][i].ButtonNum & 0x8000) { /* Axis "button" */ - sprintf(stmp, "%ca%i", + snprintf(stmp, sizeof(stmp), "%ca%i", (bmap[c][i].ButtonNum & 0x4000) ? '-' : '+', bmap[c][i].ButtonNum & 0x3FFF); } else { /* Button */ - sprintf(stmp, "b%i", bmap[c][i].ButtonNum); + snprintf(stmp, sizeof(stmp), "b%i", bmap[c][i].ButtonNum); } } output.append(buttonNames[i]); @@ -1034,26 +1034,26 @@ int GamePad_t::saveCurrentMapToFile(const char *name) stmp[k] = keyName[j]; k++; j++; } stmp[k] = 0; - //sprintf(stmp, "k%s", SDL_GetKeyName(fk->bmap[i].ButtonNum)); + //snprintf(stmp, sizeof(stmp), "k%s", SDL_GetKeyName(fk->bmap[i].ButtonNum)); } else { if (fk->bmap[i].ButtonNum & 0x2000) { /* Hat "button" */ - sprintf(stmp, "h%i.%i", + snprintf(stmp, sizeof(stmp), "h%i.%i", (fk->bmap[i].ButtonNum >> 8) & 0x1F, fk->bmap[i].ButtonNum & 0xFF); } else if (fk->bmap[i].ButtonNum & 0x8000) { /* Axis "button" */ - sprintf(stmp, "%ca%i", + snprintf(stmp, sizeof(stmp), "%ca%i", (fk->bmap[i].ButtonNum & 0x4000) ? '-' : '+', fk->bmap[i].ButtonNum & 0x3FFF); } else { /* Button */ - sprintf(stmp, "b%i", fk->bmap[i].ButtonNum); + snprintf(stmp, sizeof(stmp), "b%i", fk->bmap[i].ButtonNum); } } if ( i == 0 ) diff --git a/src/emufile.h b/src/emufile.h index 623f6c21..b5adab78 100644 --- a/src/emufile.h +++ b/src/emufile.h @@ -177,7 +177,7 @@ public: va_end(argptr); va_start(argptr, format); - vsprintf(tempbuf,format,argptr); + vsnprintf(tempbuf,amt+1,format,argptr); fwrite(tempbuf,amt); delete[] tempbuf; diff --git a/src/fds.cpp b/src/fds.cpp index 532dc14c..885728fb 100644 --- a/src/fds.cpp +++ b/src/fds.cpp @@ -866,8 +866,8 @@ int FDSLoad(const char *name, FCEUFILE *fp) { FDSSoundStateAdd(); for (x = 0; x < TotalSides; x++) { - char temp[5]; - sprintf(temp, "DDT%d", x); + char temp[8]; + snprintf(temp, sizeof(temp), "DDT%d", x); AddExState(diskdata[x], 65500, 0, temp); } diff --git a/src/file.cpp b/src/file.cpp index ef3e2c14..ae4b5301 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -148,7 +148,7 @@ end: std::string FCEU_MakeIpsFilename(FileBaseInfo fbi) { char ret[FILENAME_MAX] = ""; - sprintf(ret,"%s" PSS "%s%s.ips",fbi.filebasedirectory.c_str(),fbi.filebase.c_str(),fbi.ext.c_str()); + snprintf(ret, sizeof(ret), "%s" PSS "%s%s.ips",fbi.filebasedirectory.c_str(),fbi.filebase.c_str(),fbi.ext.c_str()); return ret; } @@ -618,9 +618,9 @@ std::string FCEU_MakeFName(int type, int id1, const char *cd1) struct stat fileInfo; do { if(odirs[FCEUIOD_MOVIES]) - sprintf(ret,"%s" PSS "%s-%d.fm2",odirs[FCEUIOD_MOVIES],FileBase, id1); + snprintf(ret, sizeof(ret), "%s" PSS "%s-%d.fm2",odirs[FCEUIOD_MOVIES],FileBase, id1); else - sprintf(ret,"%s" PSS "movies" PSS "%s-%d.fm2",BaseDirectory.c_str(),FileBase, id1); + snprintf(ret, sizeof(ret), "%s" PSS "movies" PSS "%s-%d.fm2",BaseDirectory.c_str(),FileBase, id1); id1++; } while (stat(ret, &fileInfo) == 0); break; @@ -644,19 +644,19 @@ std::string FCEU_MakeFName(int type, int id1, const char *cd1) if(odirs[FCEUIOD_STATES]) { - sprintf(ret,"%s" PSS "%s%s.fc%d",odirs[FCEUIOD_STATES],FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "%s%s.fc%d",odirs[FCEUIOD_STATES],FileBase,mfn,id1); } else { - sprintf(ret,"%s" PSS "fcs" PSS "%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "fcs" PSS "%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1); } if(stat(ret,&tmpstat)==-1) { if(odirs[FCEUIOD_STATES]) { - sprintf(ret,"%s" PSS "%s%s.fc%d",odirs[FCEUIOD_STATES],FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "%s%s.fc%d",odirs[FCEUIOD_STATES],FileBase,mfn,id1); } else { - sprintf(ret,"%s" PSS "fcs" PSS "%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "fcs" PSS "%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1); } } } @@ -665,46 +665,46 @@ std::string FCEU_MakeFName(int type, int id1, const char *cd1) { if(odirs[FCEUIOD_STATES]) { - sprintf(ret,"%s" PSS "%s-resume.fcs",odirs[FCEUIOD_STATES],FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "%s-resume.fcs",odirs[FCEUIOD_STATES],FileBase); } else { - sprintf(ret,"%s" PSS "fcs" PSS "%s-resume.fcs",BaseDirectory.c_str(),FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "fcs" PSS "%s-resume.fcs",BaseDirectory.c_str(),FileBase); } if(stat(ret,&tmpstat)==-1) { if(odirs[FCEUIOD_STATES]) { - sprintf(ret,"%s" PSS "%s-resume.fcs",odirs[FCEUIOD_STATES],FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "%s-resume.fcs",odirs[FCEUIOD_STATES],FileBase); } else { - sprintf(ret,"%s" PSS "fcs" PSS "%s-resume.fcs",BaseDirectory.c_str(),FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "fcs" PSS "%s-resume.fcs",BaseDirectory.c_str(),FileBase); } } } break; case FCEUMKF_SNAP: if(odirs[FCEUIOD_SNAPS]) - sprintf(ret,"%s" PSS "%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1); + snprintf(ret, sizeof(ret), "%s" PSS "%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1); else - sprintf(ret,"%s" PSS "snaps" PSS "%s-%d.%s",BaseDirectory.c_str(),FileBase,id1,cd1); + snprintf(ret, sizeof(ret), "%s" PSS "snaps" PSS "%s-%d.%s",BaseDirectory.c_str(),FileBase,id1,cd1); break; case FCEUMKF_FDS: if(odirs[FCEUIOD_NV]) - sprintf(ret,"%s" PSS "%s.fds",odirs[FCEUIOD_NV],FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "%s.fds",odirs[FCEUIOD_NV],FileBase); else - sprintf(ret,"%s" PSS "sav" PSS "%s.fds",BaseDirectory.c_str(),FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "sav" PSS "%s.fds",BaseDirectory.c_str(),FileBase); break; case FCEUMKF_SAV: if(odirs[FCEUIOD_NV]) - sprintf(ret,"%s" PSS "%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); + snprintf(ret, sizeof(ret), "%s" PSS "%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); else - sprintf(ret,"%s" PSS "sav" PSS "%s.%s",BaseDirectory.c_str(),FileBase,cd1); + snprintf(ret, sizeof(ret), "%s" PSS "sav" PSS "%s.%s",BaseDirectory.c_str(),FileBase,cd1); if(stat(ret,&tmpstat)==-1) { if(odirs[FCEUIOD_NV]) - sprintf(ret,"%s" PSS "%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); + snprintf(ret, sizeof(ret), "%s" PSS "%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); else - sprintf(ret,"%s" PSS "sav" PSS "%s.%s",BaseDirectory.c_str(),FileBase,cd1); + snprintf(ret, sizeof(ret), "%s" PSS "sav" PSS "%s.%s",BaseDirectory.c_str(),FileBase,cd1); } break; case FCEUMKF_AUTOSTATE: @@ -722,52 +722,52 @@ std::string FCEU_MakeFName(int type, int id1, const char *cd1) if(odirs[FCEUIOD_STATES]) { - sprintf(ret,"%s" PSS "%s%s-autosave%d.fcs",odirs[FCEUIOD_STATES],FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "%s%s-autosave%d.fcs",odirs[FCEUIOD_STATES],FileBase,mfn,id1); } else { - sprintf(ret,"%s" PSS "fcs" PSS "%s%s-autosave%d.fcs",BaseDirectory.c_str(),FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "fcs" PSS "%s%s-autosave%d.fcs",BaseDirectory.c_str(),FileBase,mfn,id1); } if(stat(ret,&tmpstat)==-1) { if(odirs[FCEUIOD_STATES]) { - sprintf(ret,"%s" PSS "%s%s-autosave%d.fcs",odirs[FCEUIOD_STATES],FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "%s%s-autosave%d.fcs",odirs[FCEUIOD_STATES],FileBase,mfn,id1); } else { - sprintf(ret,"%s" PSS "fcs" PSS "%s%s-autosave%d.fcs",BaseDirectory.c_str(),FileBase,mfn,id1); + snprintf(ret, sizeof(ret), "%s" PSS "fcs" PSS "%s%s-autosave%d.fcs",BaseDirectory.c_str(),FileBase,mfn,id1); } } break; case FCEUMKF_CHEAT: if(odirs[FCEUIOD_CHEATS]) - sprintf(ret,"%s" PSS "%s.cht",odirs[FCEUIOD_CHEATS],FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "%s.cht",odirs[FCEUIOD_CHEATS],FileBase); else - sprintf(ret,"%s" PSS "cheats" PSS "%s.cht",BaseDirectory.c_str(),FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "cheats" PSS "%s.cht",BaseDirectory.c_str(),FileBase); break; case FCEUMKF_IPS: strcpy(ret,FCEU_MakeIpsFilename(CurrentFileBase()).c_str()); break; - case FCEUMKF_GGROM:sprintf(ret,"%s" PSS "gg.rom",BaseDirectory.c_str());break; + case FCEUMKF_GGROM:snprintf(ret, sizeof(ret), "%s" PSS "gg.rom",BaseDirectory.c_str());break; case FCEUMKF_FDSROM: if(odirs[FCEUIOD_FDSROM]) - sprintf(ret,"%s" PSS "disksys.rom",odirs[FCEUIOD_FDSROM]); + snprintf(ret, sizeof(ret), "%s" PSS "disksys.rom",odirs[FCEUIOD_FDSROM]); else - sprintf(ret,"%s" PSS "disksys.rom",BaseDirectory.c_str()); + snprintf(ret, sizeof(ret), "%s" PSS "disksys.rom",BaseDirectory.c_str()); break; - case FCEUMKF_PALETTE:sprintf(ret,"%s" PSS "%s.pal",BaseDirectory.c_str(),FileBase);break; + case FCEUMKF_PALETTE:snprintf(ret, sizeof(ret), "%s" PSS "%s.pal",BaseDirectory.c_str(),FileBase);break; case FCEUMKF_MOVIEGLOB: //these globs use ??? because we can load multiple formats if(odirs[FCEUIOD_MOVIES]) - sprintf(ret,"%s" PSS "*.???",odirs[FCEUIOD_MOVIES]); + snprintf(ret, sizeof(ret), "%s" PSS "*.???",odirs[FCEUIOD_MOVIES]); else - sprintf(ret,"%s" PSS "movies" PSS "*.???",BaseDirectory.c_str()); + snprintf(ret, sizeof(ret), "%s" PSS "movies" PSS "*.???",BaseDirectory.c_str()); break; - case FCEUMKF_MOVIEGLOB2:sprintf(ret,"%s" PSS "*.???",BaseDirectory.c_str());break; + case FCEUMKF_MOVIEGLOB2:snprintf(ret, sizeof(ret), "%s" PSS "*.???",BaseDirectory.c_str());break; case FCEUMKF_STATEGLOB: if(odirs[FCEUIOD_STATES]) - sprintf(ret,"%s" PSS "%s*.fc?",odirs[FCEUIOD_STATES],FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "%s*.fc?",odirs[FCEUIOD_STATES],FileBase); else - sprintf(ret,"%s" PSS "fcs" PSS "%s*.fc?",BaseDirectory.c_str(),FileBase); + snprintf(ret, sizeof(ret), "%s" PSS "fcs" PSS "%s*.fc?",BaseDirectory.c_str(),FileBase); break; } diff --git a/src/ines.cpp b/src/ines.cpp index 5d4427df..3dd08318 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -475,21 +475,33 @@ static void CheckHInfo(uint64 partialmd5) { if (MapperNo == 99) Mirroring = 2; - if (tofix) { - char gigastr[768]; - strcpy(gigastr, "The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); + if (tofix) + { + char tmpStr[128]; + std::string gigastr; + gigastr.reserve(768); + gigastr.assign("The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); if (tofix & 1) - sprintf(gigastr + strlen(gigastr), "The mapper number should be set to %d. ", MapperNo); - if (tofix & 2) { + { + snprintf(tmpStr, sizeof(tmpStr), "The mapper number should be set to %d. ", MapperNo); + gigastr.append(tmpStr); + } + if (tofix & 2) + { const char *mstr[3] = { "Horizontal", "Vertical", "Four-screen" }; - sprintf(gigastr + strlen(gigastr), "Mirroring should be set to \"%s\". ", mstr[Mirroring & 3]); + snprintf(tmpStr, sizeof(tmpStr), "Mirroring should be set to \"%s\". ", mstr[Mirroring & 3]); + gigastr.append(tmpStr); } if (tofix & 4) - strcat(gigastr, "The battery-backed bit should be set. "); + { + gigastr.append("The battery-backed bit should be set. "); + } if (tofix & 8) - strcat(gigastr, "This game should not have any CHR ROM. "); - strcat(gigastr, "\n"); - FCEU_printf("%s", gigastr); + { + gigastr.append("This game should not have any CHR ROM. "); + } + gigastr.append("\n"); + FCEU_printf("%s", gigastr.c_str()); } } diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 450cd94b..c9711d85 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -906,7 +906,7 @@ static void LuaStackToBinaryConverter(lua_State* L, int i, std::vector",CurrentSong,NSFHeader.TotalSongs); + snprintf(snbuf, sizeof(snbuf), "<%d/%d>",CurrentSong,NSFHeader.TotalSongs); DrawTextTrans(XBuf+82*256+4+(((31-strlen(snbuf))<<2)), 256, (uint8*)snbuf, kFgColor); { diff --git a/src/pputile.inc b/src/pputile.inc index 02da9a22..af4299b5 100644 --- a/src/pputile.inc +++ b/src/pputile.inc @@ -87,9 +87,14 @@ pshift[1] <<= 8; #else #ifdef PPU_VRC5FETCH - if(tmpd & 0x40) + if(tmpd & 0x40) { + if (CHRsize[0] == (128 * 1024)) { + // NOTE: address 128K CHR-ROM using offsets into 256K CHR-ROM data + // https://www.nesdev.org/wiki/NES_2.0_Mapper_547#Kanji_ROM_layout + vadr = ((vadr & 0x00007) << 1) | ((vadr & 0x00010) >> 4) | ((vadr & 0x3FFE0) >> 1); + } C = CHRptr[0] + vadr; - else + } else C = VRAMADR(vadr); #else C = VRAMADR(vadr); diff --git a/src/profiler.cpp b/src/profiler.cpp index 077605cc..a355f407 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -136,7 +136,7 @@ profileExecVector::profileExecVector(void) strcpy( threadName, thread->objectName().toStdString().c_str()); } #endif - sprintf( fileName, "fceux-profile-%s.log", threadName); + snprintf( fileName, sizeof(fileName), "fceux-profile-%s.log", threadName); logFp = ::fopen(fileName, "w"); @@ -212,7 +212,7 @@ int profilerFuncMap::addRecord(const char *fileNameStringLiteral, autoScopedLock aLock(_mapMtx); char lineString[64]; - sprintf( lineString, ":%i", fileLineNumber); + snprintf( lineString, sizeof(lineString), ":%i", fileLineNumber); std::string fname(fileNameStringLiteral); @@ -233,7 +233,7 @@ funcProfileRecord *profilerFuncMap::findRecord(const char *fileNameStringLiteral char lineString[64]; funcProfileRecord *rec = nullptr; - sprintf( lineString, ":%i", fileLineNumber); + snprintf( lineString, sizeof(lineString), ":%i", fileLineNumber); std::string fname(fileNameStringLiteral); diff --git a/src/state.cpp b/src/state.cpp index 622168a2..734a58c2 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -345,7 +345,7 @@ static bool ReadStateChunks(EMUFILE* is, int32 totalsize) if(!warned) { char str [256]; - sprintf(str, "Warning: Found unknown save chunk of type %d.\nThis could indicate the save state is corrupted\nor made with a different (incompatible) emulator version.", t); + snprintf(str, sizeof(str), "Warning: Found unknown save chunk of type %d.\nThis could indicate the save state is corrupted\nor made with a different (incompatible) emulator version.", t); FCEUD_PrintError(str); warned=true; } diff --git a/src/utils/StringBuilder.h b/src/utils/StringBuilder.h new file mode 100644 index 00000000..2c95e992 --- /dev/null +++ b/src/utils/StringBuilder.h @@ -0,0 +1,164 @@ +#pragma once + +#include +#include +#include + +// Faster replacement functions for sprintf. It's uglier, but much faster. +class StringBuilder +{ +public: + // Helper struct. Do not use directly. + template + struct IntInfo + { + T x; + int minLen; + char leadChar; + bool upperCase; + Prefix prefix; + }; + + inline StringBuilder(char *str) : start(str), end(str) + { + *end = '\0'; + } + + inline char *str() const + { + return start; + } + + inline size_t size() const + { + return size_t(end - start); + } + + inline StringBuilder &operator <<(char ch) + { + *(end++) = ch; + *end = '\0'; + + return *this; + } + + inline StringBuilder &operator <<(const char *src) + { + size_t len = std::strlen(src); + std::memcpy(end, src, len + 1); + + end += len; + + return *this; + } + + template + inline StringBuilder &operator <<(const IntInfo intInfo) + { + *this << intInfo.prefix; + return appendInt(intInfo.x, intInfo.minLen, intInfo.leadChar, intInfo.upperCase); + } + +protected: + inline StringBuilder &operator <<(nullptr_t) + { + return *this; + } + + template + StringBuilder &appendInt(T x, int minLen = 0, char leadChar = ' ', bool upperCase = false) + { + static_assert(Radix >= 2 && Radix <= 36, "Radix must be between 2 and 36"); + static_assert(std::is_integral::value, "T must be an integral type"); + + static const char *upperCaseDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", + *lowerCaseDigits = "0123456789abcdefghijklmnopqrstuvwxyz"; + const char *digits = upperCase ? upperCaseDigits : lowerCaseDigits; + + const bool isSigned = std::is_signed::value; + bool isNeg = isSigned && x < 0; + if (isSigned && isNeg) + // This convoluted expression is to silence an unnecessary compiler warning when unsigned + x = T(-((typename std::make_signed::type)(x))); + + unsigned i = 0; + if (x != 0) + { + do + { + end[i++] = digits[x % Radix]; + x /= Radix; + } while (x != 0); + } + else + end[i++] = '0'; + + if (isNeg) + end[i++] = '-'; + + if (minLen < 0) + { + end[i] = '\0'; + + std::reverse(end, end + i); + + for (; i < (unsigned)-minLen; i++) + end[i] = leadChar; + + end[i] = '\0'; + } + else + { + for (; i < (unsigned)minLen; i++) + end[i] = leadChar; + + end[i] = '\0'; + + std::reverse(end, end + i); + } + + end += i; + + return *this; + } + + char *start; + char *end; +}; + +// Formatters for numbers + +// Generic integer with any radius +template +inline StringBuilder::IntInfo sb_int(T x, int minLen = 0, char leadChar = ' ', bool upperCase = false) +{ + return { x, minLen, leadChar, upperCase, nullptr }; +} + +// A decimal number +template +inline StringBuilder::IntInfo<10, T> sb_dec(T x, int minLen = 0, char leadChar = ' ') +{ + return { x, minLen, leadChar, false, nullptr }; +} + +// A hex number +template +inline StringBuilder::IntInfo<16, T> sb_hex(T x, int minLen = 0, bool upperCase = true, char leadChar = '0') +{ + return { x, minLen, leadChar, upperCase, nullptr }; +} + +// An address of the basic form $%x +template +inline StringBuilder::IntInfo<16, T, char> sb_addr(T x, int minLen = 4, bool upperCase = true) +{ + return { x, minLen, '0', upperCase, '$' }; +} + +// A literal value of the form #$%x +template +inline StringBuilder::IntInfo<16, T, const char *> sb_lit(T x, int minLen = 2, bool upperCase = true) +{ + return { x, minLen, '0', upperCase, "#$" }; +} diff --git a/src/video.cpp b/src/video.cpp index b0f7dd0d..cab54fd0 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -765,7 +765,7 @@ void ShowFPS(void) if ( da > FCEUD_GetTimeFreq() ) { - sprintf(fpsmsg, "%.1f", (double)boopcount / ((double)da / FCEUD_GetTimeFreq())); + snprintf(fpsmsg, sizeof(fpsmsg), "%.1f", (double)boopcount / ((double)da / FCEUD_GetTimeFreq())); boopcount = 0; boop_ts = ts; @@ -797,7 +797,7 @@ static void FCEU_DrawPauseCountDown(uint8 *XBuf) framesPerSec = 60; } - sprintf(text, "Unpausing in %d...", (pauseFramesLeft / framesPerSec) + 1); + snprintf(text, sizeof(text), "Unpausing in %d...", (pauseFramesLeft / framesPerSec) + 1); if (text[0]) { diff --git a/src/vsuni.cpp b/src/vsuni.cpp index 0111c863..915d96b2 100644 --- a/src/vsuni.cpp +++ b/src/vsuni.cpp @@ -354,33 +354,50 @@ void FCEU_VSUniCheck(uint64 md5partial, int *MapperNo, uint8 *Mirroring) { GameInfo->vs_cswitch = 1; } - if (tofix) { - char gigastr[768]; - strcpy(gigastr, "The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); + if (tofix) + { + char tmpStr[128]; + std::string gigastr; + gigastr.reserve(768); + gigastr.assign("The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); if (tofix & 4) { - sprintf(gigastr + strlen(gigastr), "Game type should be set to Vs. System. "); + snprintf(tmpStr, sizeof(tmpStr), "Game type should be set to Vs. System. "); + gigastr.append(tmpStr); } if (tofix & 1) - sprintf(gigastr + strlen(gigastr), "The mapper number should be set to %d. ", *MapperNo); - if (tofix & 2) { + { + snprintf(tmpStr, sizeof(tmpStr), "The mapper number should be set to %d. ", *MapperNo); + gigastr.append(tmpStr); + } + if (tofix & 2) + { const char* mstr[3] = { "Horizontal", "Vertical", "Four-screen" }; - sprintf(gigastr + strlen(gigastr), "Mirroring should be set to \"%s\". ", mstr[vs->mirroring & 3]); + snprintf(tmpStr, sizeof(tmpStr), "Mirroring should be set to \"%s\". ", mstr[vs->mirroring & 3]); + gigastr.append(tmpStr); } if (tofix & 8) { const char* mstr[4] = { "Normal", "RBI Baseball protection", "TKO Boxing protection", "Super Xevious protection"}; - sprintf(gigastr + strlen(gigastr), "Vs. System type should be set to \"%s\". ", mstr[vs->type]); + snprintf(tmpStr, sizeof(tmpStr), "Vs. System type should be set to \"%s\". ", mstr[vs->type]); + gigastr.append(tmpStr); } if (tofix & 16) { const char* mstr[10] = { "Default", "RP2C04-0001", "RP2C04-0002", "RP2C04-0003", "RP2C04-0004", "RC2C03B", "RC2C05-01", "RC2C05-02" , "RC2C05-03" , "RC2C05-04" }; - sprintf(gigastr + strlen(gigastr), "Vs. System PPU should be set to \"%s\". ", mstr[vs->ppu]); + snprintf(tmpStr, sizeof(tmpStr), "Vs. System PPU should be set to \"%s\". ", mstr[vs->ppu]); + gigastr.append(tmpStr); } if (tofix & 32) - sprintf(gigastr + strlen(gigastr), "The controller type should be set to zapper. "); + { + snprintf(tmpStr, sizeof(tmpStr), "The controller type should be set to zapper. "); + gigastr.append(tmpStr); + } if (tofix & 64) - sprintf(gigastr + strlen(gigastr), "The controllers should be swapped. "); - strcat(gigastr, "\n"); - FCEU_printf("%s", gigastr); + { + snprintf(tmpStr, sizeof(tmpStr), "The controllers should be swapped. "); + gigastr.append(tmpStr); + } + gigastr.append("\n"); + FCEU_printf("%s", gigastr.c_str()); } return;