More cleanup of sprintf usage in favor of snprintf. This is to resolve deprecation warnings on Mac OSX

This commit is contained in:
harry 2024-02-24 07:27:20 -05:00
parent db8fd407ab
commit c324a82526
8 changed files with 28 additions and 28 deletions

View File

@ -2274,7 +2274,7 @@ void TasEditorWindow::exportMovieFile(void)
markerID = markersManager.getMarkerAtFrame(i); markerID = markersManager.getMarkerAtFrame(i);
if (markerID) if (markerID)
{ {
sprintf( framenum, "%i ", i ); snprintf( framenum, sizeof(framenum), "%i ", i );
//_itoa(i, framenum, 10); //_itoa(i, framenum, 10);
//strcat(framenum, " "); //strcat(framenum, " ");
subtitle = framenum; subtitle = framenum;
@ -2337,7 +2337,7 @@ void TasEditorWindow::buildRecentProjectMenu(void)
for (int i=0; i<10; i++) 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); g_config->getOption( buf, &s);
@ -2373,7 +2373,7 @@ void TasEditorWindow::saveRecentProjectMenu(void)
for (it=projList.begin(); it != projList.end(); it++) for (it=projList.begin(); it != projList.end(); it++)
{ {
s = *it; s = *it;
sprintf(buf, "SDL.RecentTasProject%02i", i); snprintf(buf, sizeof(buf), "SDL.RecentTasProject%02i", i);
g_config->setOption( buf, s->c_str() ); g_config->setOption( buf, s->c_str() );
@ -6651,7 +6651,7 @@ void QPianoRoll::paintEvent(QPaintEvent *event)
//rect = QRect( -pxLineXScroll + pxFrameColX, y, pxWidthFrameCol, pxLineSpacing ); //rect = QRect( -pxLineXScroll + pxFrameColX, y, pxWidthFrameCol, pxLineSpacing );
sprintf( stmp, "%07i", lineNum ); snprintf( stmp, sizeof(stmp), "%07i", lineNum );
rect = painter.fontMetrics().boundingRect( tr(stmp) ); rect = painter.fontMetrics().boundingRect( tr(stmp) );
@ -7492,7 +7492,7 @@ void markerDragPopup::paintEvent(QPaintEvent *event)
w = event->rect().width(); w = event->rect().width();
h = event->rect().height(); h = event->rect().height();
sprintf( txt, "%07i", rowIndex ); snprintf( txt, sizeof(txt), "%07i", rowIndex );
//painter.setFont(font); //painter.setFont(font);
//I want to make the title bar pasted on the content //I want to make the title bar pasted on the content

View File

@ -658,7 +658,7 @@ void BOOKMARKS::paintEvent(QPaintEvent *event)
} }
x = pxStartCol1 + pxCharWidth; x = pxStartCol1 + pxCharWidth;
sprintf( txt, "%i", item ); snprintf( txt, sizeof(txt), "%i", item );
painter.drawText( x, y+pxLineTextOfs, tr(txt) ); painter.drawText( x, y+pxLineTextOfs, tr(txt) );

View File

@ -1023,11 +1023,11 @@ void BRANCHES::paintEvent(QPaintEvent *event)
char framenum_string[16] = {0}; char framenum_string[16] = {0};
if (bookmarks->itemUnderMouse < TOTAL_BOOKMARKS) 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 else
{ {
sprintf( framenum_string, "%07i", currFrameCounter ); snprintf( framenum_string, sizeof(framenum_string), "%07i", currFrameCounter );
} }
x = viewRect.x() + (2 * pxBoxWidth); x = viewRect.x() + (2 * pxBoxWidth);
y = pxLineSpacing; y = pxLineSpacing;

View File

@ -522,7 +522,7 @@ int HISTORY::registerChanges(int mod_type, int start, int end, int size, const c
if (mod_type == MODTYPE_INSERTNUM) if (mod_type == MODTYPE_INSERTNUM)
{ {
snap.endFrame = start + size - 1; snap.endFrame = start + size - 1;
sprintf( framenum, "%i", size); snprintf( framenum, sizeof(framenum), "%i", size);
strcat(snap.description, framenum); strcat(snap.description, framenum);
} else } else
{ {
@ -540,12 +540,12 @@ int HISTORY::registerChanges(int mod_type, int start, int end, int size, const c
snap.endFrame = snapshots[real_pos].endFrame; snap.endFrame = snapshots[real_pos].endFrame;
// add upper and lower frame to description // add upper and lower frame to description
strcat(snap.description, " "); strcat(snap.description, " ");
sprintf( framenum, "%i", snap.startFrame); snprintf( framenum, sizeof(framenum), "%i", snap.startFrame);
strcat(snap.description, framenum); strcat(snap.description, framenum);
if (snap.endFrame > snap.startFrame) if (snap.endFrame > snap.startFrame)
{ {
strcat(snap.description, "-"); strcat(snap.description, "-");
sprintf( framenum, "%i", snap.endFrame); snprintf( framenum, sizeof(framenum), "%i", snap.endFrame);
strcat(snap.description, framenum); strcat(snap.description, framenum);
} }
// add comment if there is one specified // add comment if there is one specified
@ -570,12 +570,12 @@ int HISTORY::registerChanges(int mod_type, int start, int end, int size, const c
// don't combine // don't combine
// add upper and lower frame to description // add upper and lower frame to description
strcat(snap.description, " "); strcat(snap.description, " ");
sprintf( framenum, "%i", snap.startFrame); snprintf( framenum, sizeof(framenum), "%i", snap.startFrame);
strcat(snap.description, framenum); strcat(snap.description, framenum);
if (snap.endFrame > snap.startFrame) if (snap.endFrame > snap.startFrame)
{ {
strcat(snap.description, "-"); strcat(snap.description, "-");
sprintf( framenum, "%i", snap.endFrame); snprintf( framenum, sizeof(framenum), "%i", snap.endFrame);
strcat(snap.description, framenum); strcat(snap.description, framenum);
} }
// add comment if there is one specified // add comment if there is one specified
@ -681,7 +681,7 @@ void HISTORY::registerMarkersChange(int modificationType, int start, int end, co
// add the frame to description // add the frame to description
char framenum[16]; char framenum[16];
strcat(snap.description, " "); strcat(snap.description, " ");
sprintf( framenum, "%i", snap.startFrame); snprintf( framenum, sizeof(framenum), "%i", snap.startFrame);
strcat(snap.description, framenum); strcat(snap.description, framenum);
if (snap.endFrame > snap.startFrame || modificationType == MODTYPE_MARKER_DRAG || modificationType == MODTYPE_MARKER_SWAP) if (snap.endFrame > snap.startFrame || modificationType == MODTYPE_MARKER_DRAG || modificationType == MODTYPE_MARKER_SWAP)
{ {
@ -691,7 +691,7 @@ void HISTORY::registerMarkersChange(int modificationType, int start, int end, co
strcat(snap.description, "<->"); strcat(snap.description, "<->");
else else
strcat(snap.description, "-"); strcat(snap.description, "-");
sprintf( framenum, "%i", snap.endFrame); snprintf( framenum, sizeof(framenum), "%i", snap.endFrame);
strcat(snap.description, framenum); strcat(snap.description, framenum);
} }
// add comment if there is one specified // add comment if there is one specified
@ -718,7 +718,7 @@ void HISTORY::registerBookmarkSet(int slot, BOOKMARK& backupCopy, int oldCurrent
snap.startFrame = snap.endFrame = snap.keyFrame = bookmarks->bookmarksArray[slot].snapshot.keyFrame; snap.startFrame = snap.endFrame = snap.keyFrame = bookmarks->bookmarksArray[slot].snapshot.keyFrame;
char framenum[16]; char framenum[16];
strcat(snap.description, " "); strcat(snap.description, " ");
sprintf( framenum, "%i", snap.keyFrame); snprintf( framenum, sizeof(framenum), "%i", snap.keyFrame);
strcat(snap.description, framenum); strcat(snap.description, framenum);
if (taseditorConfig->enableHotChanges) if (taseditorConfig->enableHotChanges)
snap.inputlog.copyHotChanges(&getCurrentSnapshot().inputlog); snap.inputlog.copyHotChanges(&getCurrentSnapshot().inputlog);
@ -823,10 +823,10 @@ void HISTORY::registerRecording(int frameOfChange, uint32 joypadDifferenceBits)
} }
// add upper and lower frame to description // add upper and lower frame to description
strcat(snap->description, " "); strcat(snap->description, " ");
sprintf( framenum, "%i", snap->startFrame); snprintf( framenum, sizeof(framenum), "%i", snap->startFrame);
strcat(snap->description, framenum); strcat(snap->description, framenum);
strcat(snap->description, "-"); strcat(snap->description, "-");
sprintf( framenum, "%i", snap->endFrame); snprintf( framenum, sizeof(framenum), "%i", snap->endFrame);
strcat(snap->description, framenum); strcat(snap->description, framenum);
// truncate history here // truncate history here
historyTotalItems = historyCursorPos+1; historyTotalItems = historyCursorPos+1;
@ -860,7 +860,7 @@ void HISTORY::registerRecording(int frameOfChange, uint32 joypadDifferenceBits)
} }
// add upper frame to description // add upper frame to description
strcat(snap.description, " "); strcat(snap.description, " ");
sprintf( framenum, "%i", frameOfChange); snprintf( framenum, sizeof(framenum), "%i", frameOfChange);
strcat(snap.description, framenum); strcat(snap.description, framenum);
// set hotchanges // set hotchanges
if (taseditorConfig->enableHotChanges) if (taseditorConfig->enableHotChanges)
@ -942,7 +942,7 @@ int HISTORY::registerLuaChanges(const char* name, int start, bool insertionOrDel
// add upper frame to description // add upper frame to description
char framenum[16]; char framenum[16];
strcat(snap.description, " "); strcat(snap.description, " ");
sprintf( framenum, "%i", first_changes); snprintf( framenum, sizeof(framenum), "%i", first_changes);
strcat(snap.description, framenum); strcat(snap.description, framenum);
// set hotchanges // set hotchanges
if (taseditorConfig->enableHotChanges) if (taseditorConfig->enableHotChanges)

View File

@ -447,7 +447,7 @@ void PLAYBACK::redrawMarkerData()
strcpy(new_text, upperMarkerText); strcpy(new_text, upperMarkerText);
} }
char num[16]; char num[16];
sprintf( num, "%i", displayedMarkerNumber); snprintf( num, sizeof(num), "%i", displayedMarkerNumber);
strcat(new_text, num); strcat(new_text, num);
strcat(new_text, " "); strcat(new_text, " ");
tasWin->upperMarkerLabel->setText( QObject::tr(new_text) ); tasWin->upperMarkerLabel->setText( QObject::tr(new_text) );

View File

@ -193,7 +193,7 @@ void SELECTION::redrawMarkerData()
strcpy(new_text, lowerMarkerText); strcpy(new_text, lowerMarkerText);
} }
char num[16]; char num[16];
sprintf( num, "%i", displayedMarkerNumber); snprintf( num, sizeof(num), "%i", displayedMarkerNumber);
strcat(new_text, num); strcat(new_text, num);
strcat(new_text, " "); strcat(new_text, " ");
tasWin->lowerMarkerLabel->setText( QObject::tr(new_text) ); tasWin->lowerMarkerLabel->setText( QObject::tr(new_text) );

View File

@ -73,7 +73,7 @@ void SPLICER::update(void)
// rows // rows
if (size > 1) if (size > 1)
{ {
sprintf( num, "%i", size); snprintf( num, sizeof(num), "%i", size);
strcat(new_text, num); strcat(new_text, num);
strcat(new_text, numTextRows); strcat(new_text, numTextRows);
} }
@ -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 int columns = NUM_JOYPAD_BUTTONS * joysticksPerFrame[getInputType(currMovieData)]; // in future the number of columns will depend on selected columns
if (columns > 1) if (columns > 1)
{ {
sprintf( num, "%i", columns); snprintf( num, sizeof(num), "%i", columns);
strcat(new_text, num); strcat(new_text, num);
strcat(new_text, numTextColumns); strcat(new_text, numTextColumns);
} }
@ -787,7 +787,7 @@ void SPLICER::redrawInfoAboutClipboard(void)
// rows // rows
if (clipboardSelection.size() > 1) if (clipboardSelection.size() > 1)
{ {
sprintf( num, "%zi", clipboardSelection.size()); snprintf( num, sizeof(num), "%zi", clipboardSelection.size());
strcat(new_text, num); strcat(new_text, num);
strcat(new_text, numTextRows); strcat(new_text, numTextRows);
} }
@ -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 int columns = NUM_JOYPAD_BUTTONS * joysticksPerFrame[getInputType(currMovieData)]; // in future the number of columns will depend on selected columns
if (columns > 1) if (columns > 1)
{ {
sprintf( num, "%i", columns); snprintf( num, sizeof(num), "%i", columns);
strcat(new_text, num); strcat(new_text, num);
strcat(new_text, numTextColumns); strcat(new_text, numTextColumns);
} }

View File

@ -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.assign("This project was saved using different version of TAS Editor!\n\n");
message.append("Original version: "); message.append("Original version: ");
char versionNum[16]; char versionNum[16];
sprintf( versionNum, "%u", projectFileVersion); snprintf( versionNum, sizeof(versionNum), "%u", projectFileVersion);
message.append(versionNum); message.append(versionNum);
message.append("\nCurrent version: "); 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(versionNum);
message.append("\n\nClick Yes to try loading all data from the file (may crash).\n"); 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"); message.append("Click No to only load movie data.\n");