Skip to content

Commit

Permalink
More cleanup of sprintf usage in favor of snprintf. This is to resolv…
Browse files Browse the repository at this point in the history
…e deprecation warnings on Mac OSX
  • Loading branch information
thor2016 committed Feb 24, 2024
1 parent db8fd40 commit c324a82
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/drivers/Qt/TasEditor/TasEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ void TasEditorWindow::exportMovieFile(void)
markerID = markersManager.getMarkerAtFrame(i);
if (markerID)
{
sprintf( framenum, "%i ", i );
snprintf( framenum, sizeof(framenum), "%i ", i );
//_itoa(i, framenum, 10);
//strcat(framenum, " ");
subtitle = framenum;
Expand Down Expand Up @@ -2337,7 +2337,7 @@ void TasEditorWindow::buildRecentProjectMenu(void)

for (int i=0; i<10; i++)
{
sprintf(buf, "SDL.RecentTasProject%02i", i);
snprintf(buf, sizeof(buf), "SDL.RecentTasProject%02i", i);

g_config->getOption( buf, &s);

Expand Down Expand Up @@ -2373,7 +2373,7 @@ void TasEditorWindow::saveRecentProjectMenu(void)
for (it=projList.begin(); it != projList.end(); it++)
{
s = *it;
sprintf(buf, "SDL.RecentTasProject%02i", i);
snprintf(buf, sizeof(buf), "SDL.RecentTasProject%02i", i);

g_config->setOption( buf, s->c_str() );

Expand Down Expand Up @@ -6651,7 +6651,7 @@ void QPianoRoll::paintEvent(QPaintEvent *event)

//rect = QRect( -pxLineXScroll + pxFrameColX, y, pxWidthFrameCol, pxLineSpacing );

sprintf( stmp, "%07i", lineNum );
snprintf( stmp, sizeof(stmp), "%07i", lineNum );

rect = painter.fontMetrics().boundingRect( tr(stmp) );

Expand Down Expand Up @@ -7492,7 +7492,7 @@ void markerDragPopup::paintEvent(QPaintEvent *event)
w = event->rect().width();
h = event->rect().height();

sprintf( txt, "%07i", rowIndex );
snprintf( txt, sizeof(txt), "%07i", rowIndex );

//painter.setFont(font);
//I want to make the title bar pasted on the content
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/Qt/TasEditor/bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ void BOOKMARKS::paintEvent(QPaintEvent *event)
}

x = pxStartCol1 + pxCharWidth;
sprintf( txt, "%i", item );
snprintf( txt, sizeof(txt), "%i", item );

painter.drawText( x, y+pxLineTextOfs, tr(txt) );

Expand Down
4 changes: 2 additions & 2 deletions src/drivers/Qt/TasEditor/branches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,11 @@ void BRANCHES::paintEvent(QPaintEvent *event)
char framenum_string[16] = {0};
if (bookmarks->itemUnderMouse < TOTAL_BOOKMARKS)
{
sprintf( framenum_string, "%07i", bookmarks->bookmarksArray[bookmarks->itemUnderMouse].snapshot.keyFrame );
snprintf( framenum_string, sizeof(framenum_string), "%07i", bookmarks->bookmarksArray[bookmarks->itemUnderMouse].snapshot.keyFrame );
}
else
{
sprintf( framenum_string, "%07i", currFrameCounter );
snprintf( framenum_string, sizeof(framenum_string), "%07i", currFrameCounter );
}
x = viewRect.x() + (2 * pxBoxWidth);
y = pxLineSpacing;
Expand Down
24 changes: 12 additions & 12 deletions src/drivers/Qt/TasEditor/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ int HISTORY::registerChanges(int mod_type, int start, int end, int size, const c
if (mod_type == MODTYPE_INSERTNUM)
{
snap.endFrame = start + size - 1;
sprintf( framenum, "%i", size);
snprintf( framenum, sizeof(framenum), "%i", size);
strcat(snap.description, framenum);
} else
{
Expand All @@ -540,12 +540,12 @@ int HISTORY::registerChanges(int mod_type, int start, int end, int size, const c
snap.endFrame = snapshots[real_pos].endFrame;
// add upper and lower frame to description
strcat(snap.description, " ");
sprintf( framenum, "%i", snap.startFrame);
snprintf( framenum, sizeof(framenum), "%i", snap.startFrame);
strcat(snap.description, framenum);
if (snap.endFrame > snap.startFrame)
{
strcat(snap.description, "-");
sprintf( framenum, "%i", snap.endFrame);
snprintf( framenum, sizeof(framenum), "%i", snap.endFrame);
strcat(snap.description, framenum);
}
// add comment if there is one specified
Expand All @@ -570,12 +570,12 @@ int HISTORY::registerChanges(int mod_type, int start, int end, int size, const c
// don't combine
// add upper and lower frame to description
strcat(snap.description, " ");
sprintf( framenum, "%i", snap.startFrame);
snprintf( framenum, sizeof(framenum), "%i", snap.startFrame);
strcat(snap.description, framenum);
if (snap.endFrame > snap.startFrame)
{
strcat(snap.description, "-");
sprintf( framenum, "%i", snap.endFrame);
snprintf( framenum, sizeof(framenum), "%i", snap.endFrame);
strcat(snap.description, framenum);
}
// add comment if there is one specified
Expand Down Expand Up @@ -681,7 +681,7 @@ void HISTORY::registerMarkersChange(int modificationType, int start, int end, co
// add the frame to description
char framenum[16];
strcat(snap.description, " ");
sprintf( framenum, "%i", snap.startFrame);
snprintf( framenum, sizeof(framenum), "%i", snap.startFrame);
strcat(snap.description, framenum);
if (snap.endFrame > snap.startFrame || modificationType == MODTYPE_MARKER_DRAG || modificationType == MODTYPE_MARKER_SWAP)
{
Expand All @@ -691,7 +691,7 @@ void HISTORY::registerMarkersChange(int modificationType, int start, int end, co
strcat(snap.description, "<->");
else
strcat(snap.description, "-");
sprintf( framenum, "%i", snap.endFrame);
snprintf( framenum, sizeof(framenum), "%i", snap.endFrame);
strcat(snap.description, framenum);
}
// add comment if there is one specified
Expand All @@ -718,7 +718,7 @@ void HISTORY::registerBookmarkSet(int slot, BOOKMARK& backupCopy, int oldCurrent
snap.startFrame = snap.endFrame = snap.keyFrame = bookmarks->bookmarksArray[slot].snapshot.keyFrame;
char framenum[16];
strcat(snap.description, " ");
sprintf( framenum, "%i", snap.keyFrame);
snprintf( framenum, sizeof(framenum), "%i", snap.keyFrame);
strcat(snap.description, framenum);
if (taseditorConfig->enableHotChanges)
snap.inputlog.copyHotChanges(&getCurrentSnapshot().inputlog);
Expand Down Expand Up @@ -823,10 +823,10 @@ void HISTORY::registerRecording(int frameOfChange, uint32 joypadDifferenceBits)
}
// add upper and lower frame to description
strcat(snap->description, " ");
sprintf( framenum, "%i", snap->startFrame);
snprintf( framenum, sizeof(framenum), "%i", snap->startFrame);
strcat(snap->description, framenum);
strcat(snap->description, "-");
sprintf( framenum, "%i", snap->endFrame);
snprintf( framenum, sizeof(framenum), "%i", snap->endFrame);
strcat(snap->description, framenum);
// truncate history here
historyTotalItems = historyCursorPos+1;
Expand Down Expand Up @@ -860,7 +860,7 @@ void HISTORY::registerRecording(int frameOfChange, uint32 joypadDifferenceBits)
}
// add upper frame to description
strcat(snap.description, " ");
sprintf( framenum, "%i", frameOfChange);
snprintf( framenum, sizeof(framenum), "%i", frameOfChange);
strcat(snap.description, framenum);
// set hotchanges
if (taseditorConfig->enableHotChanges)
Expand Down Expand Up @@ -942,7 +942,7 @@ int HISTORY::registerLuaChanges(const char* name, int start, bool insertionOrDel
// add upper frame to description
char framenum[16];
strcat(snap.description, " ");
sprintf( framenum, "%i", first_changes);
snprintf( framenum, sizeof(framenum), "%i", first_changes);
strcat(snap.description, framenum);
// set hotchanges
if (taseditorConfig->enableHotChanges)
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/Qt/TasEditor/playback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ void PLAYBACK::redrawMarkerData()
strcpy(new_text, upperMarkerText);
}
char num[16];
sprintf( num, "%i", displayedMarkerNumber);
snprintf( num, sizeof(num), "%i", displayedMarkerNumber);
strcat(new_text, num);
strcat(new_text, " ");
tasWin->upperMarkerLabel->setText( QObject::tr(new_text) );
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/Qt/TasEditor/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void SELECTION::redrawMarkerData()
strcpy(new_text, lowerMarkerText);
}
char num[16];
sprintf( num, "%i", displayedMarkerNumber);
snprintf( num, sizeof(num), "%i", displayedMarkerNumber);
strcat(new_text, num);
strcat(new_text, " ");
tasWin->lowerMarkerLabel->setText( QObject::tr(new_text) );
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/Qt/TasEditor/splicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void SPLICER::update(void)
// rows
if (size > 1)
{
sprintf( num, "%i", size);
snprintf( num, sizeof(num), "%i", size);
strcat(new_text, num);
strcat(new_text, numTextRows);
}
Expand All @@ -85,7 +85,7 @@ void SPLICER::update(void)
int columns = NUM_JOYPAD_BUTTONS * joysticksPerFrame[getInputType(currMovieData)]; // in future the number of columns will depend on selected columns
if (columns > 1)
{
sprintf( num, "%i", columns);
snprintf( num, sizeof(num), "%i", columns);
strcat(new_text, num);
strcat(new_text, numTextColumns);
}
Expand Down Expand Up @@ -787,7 +787,7 @@ void SPLICER::redrawInfoAboutClipboard(void)
// rows
if (clipboardSelection.size() > 1)
{
sprintf( num, "%zi", clipboardSelection.size());
snprintf( num, sizeof(num), "%zi", clipboardSelection.size());
strcat(new_text, num);
strcat(new_text, numTextRows);
}
Expand All @@ -799,7 +799,7 @@ void SPLICER::redrawInfoAboutClipboard(void)
int columns = NUM_JOYPAD_BUTTONS * joysticksPerFrame[getInputType(currMovieData)]; // in future the number of columns will depend on selected columns
if (columns > 1)
{
sprintf( num, "%i", columns);
snprintf( num, sizeof(num), "%i", columns);
strcat(new_text, num);
strcat(new_text, numTextColumns);
}
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/Qt/TasEditor/taseditor_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ bool TASEDITOR_PROJECT::load(const char* fullName)
message.assign("This project was saved using different version of TAS Editor!\n\n");
message.append("Original version: ");
char versionNum[16];
sprintf( versionNum, "%u", projectFileVersion);
snprintf( versionNum, sizeof(versionNum), "%u", projectFileVersion);
message.append(versionNum);
message.append("\nCurrent version: ");
sprintf( versionNum, "%i", PROJECT_FILE_CURRENT_VERSION);
snprintf( versionNum, sizeof(versionNum), "%i", PROJECT_FILE_CURRENT_VERSION);
message.append(versionNum);
message.append("\n\nClick Yes to try loading all data from the file (may crash).\n");
message.append("Click No to only load movie data.\n");
Expand Down

0 comments on commit c324a82

Please sign in to comment.