Skip to content

Commit

Permalink
change usages of deprecated sprintf to snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiaholmquist committed Dec 25, 2024
1 parent 3950424 commit 212286e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/ARMJIT_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ ARMJIT_Memory::ARMJIT_Memory(melonDS::NDS& nds) : NDS(nds)
}
#else
char fastmemPidName[snprintf(NULL, 0, "/melondsfastmem%d", getpid()) + 1];
sprintf(fastmemPidName, "/melondsfastmem%d", getpid());
snprintf(fastmemPidName, sizeof(fastmemPidName), "/melondsfastmem%d", getpid());
MemoryFile = shm_open(fastmemPidName, O_RDWR | O_CREAT | O_EXCL, 0600);
if (MemoryFile == -1)
{
Expand Down Expand Up @@ -1600,4 +1600,4 @@ void* ARMJIT_Memory::GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) co
}
return NULL;
}
}
}
8 changes: 4 additions & 4 deletions src/frontend/qt_sdl/EmuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ void EmuThread::run()
double actualfps = (59.8261 * 263.0) / nlines;
int inst = emuInstance->instanceID;
if (inst == 0)
sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, actualfps);
snprintf(melontitle, sizeof(melontitle), "[%d/%.0f] melonDS " MELONDS_VERSION, fps, actualfps);
else
sprintf(melontitle, "[%d/%.0f] melonDS (%d)", fps, fpstarget, inst+1);
snprintf(melontitle, sizeof(melontitle), "[%d/%.0f] melonDS (%d)", fps, fpstarget, inst+1);
changeWindowTitle(melontitle);
}
}
Expand All @@ -445,9 +445,9 @@ void EmuThread::run()

int inst = emuInstance->instanceID;
if (inst == 0)
sprintf(melontitle, "melonDS " MELONDS_VERSION);
snprintf(melontitle, sizeof(melontitle), "melonDS " MELONDS_VERSION);
else
sprintf(melontitle, "melonDS (%d)", inst+1);
snprintf(melontitle, sizeof(melontitle), "melonDS (%d)", inst+1);
changeWindowTitle(melontitle);

SDL_Delay(75);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/qt_sdl/NetplayDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void NetplayDialog::doUpdatePlayerList(Netplay::Player* players, int num)

char ip[32];
u32 addr = player->Address;
sprintf(ip, "%d.%d.%d.%d", addr&0xFF, (addr>>8)&0xFF, (addr>>16)&0xFF, addr>>24);
snprintf(ip, sizeof(ip), "%d.%d.%d.%d", addr&0xFF, (addr>>8)&0xFF, (addr>>16)&0xFF, addr>>24);
model->setItem(i, 4, new QStandardItem(ip));
}
}
4 changes: 2 additions & 2 deletions src/frontend/qt_sdl/TitleManagerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void TitleManagerDialog::createTitleItem(u32 category, u32 titleid)
*(u32*)&gamecode[0] = *(u32*)&header.GameCode[0];
gamecode[4] = '\0';
char extra[128];
sprintf(extra, "\n(title ID: %s · %08x/%08x · version %08x)", gamecode, category, titleid, version);
snprintf(extra, sizeof(extra), "\n(title ID: %s · %08x/%08x · version %08x)", gamecode, category, titleid, version);

QListWidgetItem* item = new QListWidgetItem(title + QString(extra));
item->setIcon(icon);
Expand Down Expand Up @@ -482,7 +482,7 @@ void TitleImportDialog::accept()
network = new QNetworkAccessManager(this);

char url[256];
sprintf(url, "http://nus.cdn.t.shop.nintendowifi.net/ccs/download/%08x%08x/tmd", titleid[1], titleid[0]);
snprintf(url, sizeof(url), "http://nus.cdn.t.shop.nintendowifi.net/ccs/download/%08x%08x/tmd", titleid[1], titleid[0]);

QNetworkRequest req;
req.setUrl(QUrl(url));
Expand Down
12 changes: 6 additions & 6 deletions src/frontend/qt_sdl/WifiSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ void WifiSettingsDialog::on_cbxDirectAdapter_currentIndexChanged(int sel)
melonDS::AdapterData* adapter = &adapters[sel];
char tmp[64];

sprintf(tmp, "%02X:%02X:%02X:%02X:%02X:%02X",
adapter->MAC[0], adapter->MAC[1], adapter->MAC[2],
adapter->MAC[3], adapter->MAC[4], adapter->MAC[5]);
snprintf(tmp, sizeof(tmp), "%02X:%02X:%02X:%02X:%02X:%02X",
adapter->MAC[0], adapter->MAC[1], adapter->MAC[2],
adapter->MAC[3], adapter->MAC[4], adapter->MAC[5]);
ui->lblAdapterMAC->setText(QString(tmp));

sprintf(tmp, "%d.%d.%d.%d",
adapter->IP_v4[0], adapter->IP_v4[1],
adapter->IP_v4[2], adapter->IP_v4[3]);
snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d",
adapter->IP_v4[0], adapter->IP_v4[1],
adapter->IP_v4[2], adapter->IP_v4[3]);
ui->lblAdapterIP->setText(QString(tmp));
}

Expand Down

0 comments on commit 212286e

Please sign in to comment.