Skip to content

Commit 7b79d9d

Browse files
committed
Partial cleanup of sprintf usage in favor of snprintf. This is to resolve deprecation warnings on Mac OSX
1 parent 80f17c6 commit 7b79d9d

13 files changed

+146
-117
lines changed

src/asm.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ char *Disassemble(int addr, uint8 *opcode) {
286286

287287
#ifdef BRK_3BYTE_HACK
288288
case 0x00:
289-
sprintf(str,"BRK %02X %02X", opcode[1], opcode[2]);
289+
snprintf(str, sizeof(str), "BRK %02X %02X", opcode[1], opcode[2]);
290290
break;
291291
#else
292292
case 0x00: strcpy(str,"BRK"); break;
@@ -333,7 +333,7 @@ char *Disassemble(int addr, uint8 *opcode) {
333333
case 0xE1: strcpy(chr,"SBC"); goto _indirectx;
334334
_indirectx:
335335
indirectX(tmp);
336-
sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
336+
snprintf(str, sizeof(str), "%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
337337
break;
338338

339339
//Zero Page
@@ -361,7 +361,7 @@ char *Disassemble(int addr, uint8 *opcode) {
361361
_zeropage:
362362
// ################################## Start of SP CODE ###########################
363363
// Change width to %04X // don't!
364-
sprintf(str,"%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1]));
364+
snprintf(str, sizeof(str), "%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1]));
365365
// ################################## End of SP CODE ###########################
366366
break;
367367

@@ -379,7 +379,7 @@ char *Disassemble(int addr, uint8 *opcode) {
379379
case 0xE0: strcpy(chr,"CPX"); goto _immediate;
380380
case 0xE9: strcpy(chr,"SBC"); goto _immediate;
381381
_immediate:
382-
sprintf(str,"%s #$%02X", chr,opcode[1]);
382+
snprintf(str, sizeof(str), "%s #$%02X", chr,opcode[1]);
383383
break;
384384

385385
//Absolute
@@ -406,7 +406,7 @@ char *Disassemble(int addr, uint8 *opcode) {
406406
case 0xEE: strcpy(chr,"INC"); goto _absolute;
407407
_absolute:
408408
absolute(tmp);
409-
sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp));
409+
snprintf(str, sizeof(str), "%s $%04X = #$%02X", chr,tmp,GetMem(tmp));
410410
break;
411411

412412
//branches
@@ -420,7 +420,7 @@ char *Disassemble(int addr, uint8 *opcode) {
420420
case 0xF0: strcpy(chr,"BEQ"); goto _branch;
421421
_branch:
422422
relative(tmp);
423-
sprintf(str,"%s $%04X", chr,tmp);
423+
snprintf(str, sizeof(str), "%s $%04X", chr,tmp);
424424
break;
425425

426426
//(Indirect),Y
@@ -434,7 +434,7 @@ char *Disassemble(int addr, uint8 *opcode) {
434434
case 0xF1: strcpy(chr,"SBC"); goto _indirecty;
435435
_indirecty:
436436
indirectY(tmp);
437-
sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
437+
snprintf(str, sizeof(str), "%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
438438
break;
439439

440440
//Zero Page,X
@@ -458,7 +458,7 @@ char *Disassemble(int addr, uint8 *opcode) {
458458
zpIndex(tmp,RX);
459459
// ################################## Start of SP CODE ###########################
460460
// Change width to %04X // don't!
461-
sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
461+
snprintf(str, sizeof(str), "%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
462462
// ################################## End of SP CODE ###########################
463463
break;
464464

@@ -475,7 +475,7 @@ char *Disassemble(int addr, uint8 *opcode) {
475475
_absolutey:
476476
absolute(tmp);
477477
tmp2=(tmp+RY);
478-
sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
478+
snprintf(str, sizeof(str), "%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
479479
break;
480480

481481
//Absolute,X
@@ -497,16 +497,16 @@ char *Disassemble(int addr, uint8 *opcode) {
497497
_absolutex:
498498
absolute(tmp);
499499
tmp2=(tmp+RX);
500-
sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
500+
snprintf(str, sizeof(str), "%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
501501
break;
502502

503503
//jumps
504504
case 0x20: strcpy(chr,"JSR"); goto _jump;
505505
case 0x4C: strcpy(chr,"JMP"); goto _jump;
506-
case 0x6C: absolute(tmp); sprintf(str,"JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break;
506+
case 0x6C: absolute(tmp); snprintf(str, sizeof(str), "JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break;
507507
_jump:
508508
absolute(tmp);
509-
sprintf(str,"%s $%04X", chr,tmp);
509+
snprintf(str, sizeof(str), "%s $%04X", chr,tmp);
510510
break;
511511

512512
//Zero Page,Y
@@ -516,7 +516,7 @@ char *Disassemble(int addr, uint8 *opcode) {
516516
zpIndex(tmp,RY);
517517
// ################################## Start of SP CODE ###########################
518518
// Change width to %04X // don't!
519-
sprintf(str,"%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
519+
snprintf(str, sizeof(str), "%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
520520
// ################################## End of SP CODE ###########################
521521
break;
522522

src/drivers/Qt/AboutWindow.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ AboutWindow::AboutWindow(QWidget *parent)
130130

131131
mainLayout->addLayout( hbox1 );
132132

133-
sprintf( stmp, "git URL: %s", fceu_get_git_url() );
133+
snprintf( stmp, sizeof(stmp), "git URL: %s", fceu_get_git_url() );
134134

135135
hbox1 = new QHBoxLayout();
136136
lbl = new QLabel( tr(stmp) );
@@ -140,7 +140,7 @@ AboutWindow::AboutWindow(QWidget *parent)
140140

141141
mainLayout->addLayout( hbox1 );
142142

143-
sprintf( stmp, "git Revision: %s", fceu_get_git_rev() );
143+
snprintf( stmp, sizeof(stmp), "git Revision: %s", fceu_get_git_rev() );
144144

145145
hbox1 = new QHBoxLayout();
146146
lbl = new QLabel( tr(stmp) );
@@ -191,23 +191,23 @@ AboutWindow::AboutWindow(QWidget *parent)
191191

192192
credits->insertPlainText( "\nOpen Source Dependencies:\n" );
193193

194-
sprintf( stmp, " Compiled with Qt version %d.%d.%d\n", QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH );
194+
snprintf( stmp, sizeof(stmp), " Compiled with Qt version %d.%d.%d\n", QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH );
195195
credits->insertPlainText( stmp );
196196

197-
sprintf( stmp, " Compiled with SDL version %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL );
197+
snprintf( stmp, sizeof(stmp), " Compiled with SDL version %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL );
198198
credits->insertPlainText( stmp );
199199

200200
SDL_version v;
201201
SDL_GetVersion(&v);
202-
sprintf( stmp, " Linked with SDL version %d.%d.%d\n", v.major, v.minor, v.patch);
202+
snprintf( stmp, sizeof(stmp), " Linked with SDL version %d.%d.%d\n", v.major, v.minor, v.patch);
203203
credits->insertPlainText( stmp );
204204

205205
#ifdef ZLIB_VERSION
206-
sprintf( stmp, " Compiled with zlib %s\n", ZLIB_VERSION );
206+
snprintf( stmp, sizeof(stmp), " Compiled with zlib %s\n", ZLIB_VERSION );
207207
credits->insertPlainText( stmp );
208208
#endif
209209
#ifdef _USE_LIBARCHIVE
210-
sprintf( stmp, " Compiled with libarchive %s\n", ARCHIVE_VERSION_ONLY_STRING );
210+
snprintf( stmp, sizeof(stmp), " Compiled with libarchive %s\n", ARCHIVE_VERSION_ONLY_STRING );
211211
credits->insertPlainText( stmp );
212212
const char *libArcName[] = { "zlib", "liblzma", "bzlib", "liblz4", "libzstd", nullptr };
213213
const char *libArcVersion[] = { archive_zlib_version(), archive_liblzma_version(),
@@ -217,35 +217,35 @@ AboutWindow::AboutWindow(QWidget *parent)
217217
{
218218
if (libArcVersion[i])
219219
{
220-
sprintf( stmp, " %s %s\n", libArcName[i], libArcVersion[i]);
220+
snprintf( stmp, sizeof(stmp), " %s %s\n", libArcName[i], libArcVersion[i]);
221221
credits->insertPlainText( stmp );
222222
}
223223
i++;
224224
}
225225
#endif
226226

227227
#ifdef _S9XLUA_H
228-
sprintf( stmp, " Compiled with %s\n", LUA_RELEASE );
228+
snprintf( stmp, sizeof(stmp), " Compiled with %s\n", LUA_RELEASE );
229229
credits->insertPlainText( stmp );
230230
#endif
231231

232232
#ifdef _USE_LIBAV
233-
sprintf( stmp, " Compiled with ffmpeg libraries:\n");
233+
snprintf( stmp, sizeof(stmp), " Compiled with ffmpeg libraries:\n");
234234
credits->insertPlainText( stmp );
235-
sprintf( stmp, " libavutil %i.%i.%i\n", LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO);
235+
snprintf( stmp, sizeof(stmp), " libavutil %i.%i.%i\n", LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO);
236236
credits->insertPlainText( stmp );
237-
sprintf( stmp, " libavformat %i.%i.%i\n", LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO);
237+
snprintf( stmp, sizeof(stmp), " libavformat %i.%i.%i\n", LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO);
238238
credits->insertPlainText( stmp );
239-
sprintf( stmp, " libavcodec %i.%i.%i\n", LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO);
239+
snprintf( stmp, sizeof(stmp), " libavcodec %i.%i.%i\n", LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO);
240240
credits->insertPlainText( stmp );
241-
sprintf( stmp, " libswscale %i.%i.%i\n", LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
241+
snprintf( stmp, sizeof(stmp), " libswscale %i.%i.%i\n", LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
242242
credits->insertPlainText( stmp );
243-
sprintf( stmp, " libswresample %i.%i.%i\n", LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR, LIBSWRESAMPLE_VERSION_MICRO);
243+
snprintf( stmp, sizeof(stmp), " libswresample %i.%i.%i\n", LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR, LIBSWRESAMPLE_VERSION_MICRO);
244244
credits->insertPlainText( stmp );
245245
#endif
246246

247247
#ifdef _USE_X264
248-
sprintf( stmp, " Compiled with x264 version %s\n", X264_POINTVER );
248+
snprintf( stmp, sizeof(stmp), " Compiled with x264 version %s\n", X264_POINTVER );
249249
credits->insertPlainText( stmp );
250250
#endif
251251

src/drivers/Qt/sdl-joystick.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ int GamePad_t::saveCurrentMapToFile(const char *name)
946946
output.append(name);
947947
output.append(",");
948948
output.append("config:");
949-
sprintf( stmp, "%i,", c );
949+
snprintf( stmp, sizeof(stmp), "%i,", c );
950950
output.append(stmp);
951951

952952
for (i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
@@ -970,26 +970,26 @@ int GamePad_t::saveCurrentMapToFile(const char *name)
970970
}
971971
stmp[k] = 0;
972972

973-
//sprintf(stmp, "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum));
973+
//snprintf(stmp, sizeof(stmp), "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum));
974974
}
975975
else
976976
{
977977
if (bmap[c][i].ButtonNum & 0x2000)
978978
{
979979
/* Hat "button" */
980-
sprintf(stmp, "h%i.%i",
980+
snprintf(stmp, sizeof(stmp), "h%i.%i",
981981
(bmap[c][i].ButtonNum >> 8) & 0x1F, bmap[c][i].ButtonNum & 0xFF);
982982
}
983983
else if (bmap[c][i].ButtonNum & 0x8000)
984984
{
985985
/* Axis "button" */
986-
sprintf(stmp, "%ca%i",
986+
snprintf(stmp, sizeof(stmp), "%ca%i",
987987
(bmap[c][i].ButtonNum & 0x4000) ? '-' : '+', bmap[c][i].ButtonNum & 0x3FFF);
988988
}
989989
else
990990
{
991991
/* Button */
992-
sprintf(stmp, "b%i", bmap[c][i].ButtonNum);
992+
snprintf(stmp, sizeof(stmp), "b%i", bmap[c][i].ButtonNum);
993993
}
994994
}
995995
output.append(buttonNames[i]);
@@ -1034,26 +1034,26 @@ int GamePad_t::saveCurrentMapToFile(const char *name)
10341034
stmp[k] = keyName[j]; k++; j++;
10351035
}
10361036
stmp[k] = 0;
1037-
//sprintf(stmp, "k%s", SDL_GetKeyName(fk->bmap[i].ButtonNum));
1037+
//snprintf(stmp, sizeof(stmp), "k%s", SDL_GetKeyName(fk->bmap[i].ButtonNum));
10381038
}
10391039
else
10401040
{
10411041
if (fk->bmap[i].ButtonNum & 0x2000)
10421042
{
10431043
/* Hat "button" */
1044-
sprintf(stmp, "h%i.%i",
1044+
snprintf(stmp, sizeof(stmp), "h%i.%i",
10451045
(fk->bmap[i].ButtonNum >> 8) & 0x1F, fk->bmap[i].ButtonNum & 0xFF);
10461046
}
10471047
else if (fk->bmap[i].ButtonNum & 0x8000)
10481048
{
10491049
/* Axis "button" */
1050-
sprintf(stmp, "%ca%i",
1050+
snprintf(stmp, sizeof(stmp), "%ca%i",
10511051
(fk->bmap[i].ButtonNum & 0x4000) ? '-' : '+', fk->bmap[i].ButtonNum & 0x3FFF);
10521052
}
10531053
else
10541054
{
10551055
/* Button */
1056-
sprintf(stmp, "b%i", fk->bmap[i].ButtonNum);
1056+
snprintf(stmp, sizeof(stmp), "b%i", fk->bmap[i].ButtonNum);
10571057
}
10581058
}
10591059
if ( i == 0 )

src/fds.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,8 @@ int FDSLoad(const char *name, FCEUFILE *fp) {
866866
FDSSoundStateAdd();
867867

868868
for (x = 0; x < TotalSides; x++) {
869-
char temp[5];
870-
sprintf(temp, "DDT%d", x);
869+
char temp[8];
870+
snprintf(temp, sizeof(temp), "DDT%d", x);
871871
AddExState(diskdata[x], 65500, 0, temp);
872872
}
873873

0 commit comments

Comments
 (0)