Skip to content

Commit

Permalink
bugfix: fix _sntprintf sizeof references
Browse files Browse the repository at this point in the history
Some sizes were too short, resulting in cut-off values
  • Loading branch information
midwan committed Feb 8, 2025
1 parent 726a3f9 commit f706383
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/cfgfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ static void write_filesys_config (struct uae_prefs *p, struct zfile *f)
}
}
if (ci->controller_type_unit > 0)
_sntprintf(hdcs + _tcslen(hdcs), sizeof hdcs, _T("-%d"), ci->controller_type_unit + 1);
_sntprintf(hdcs + _tcslen(hdcs), sizeof hdcs + _tcslen(hdcs), _T("-%d"), ci->controller_type_unit + 1);

auto* str1b = cfgfile_escape (str1, _T(":,"), true, false);
auto* str1c = cfgfile_escape_min(str1);
Expand Down Expand Up @@ -2603,15 +2603,15 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type)
if (tmp[0]) {
_tcscat(tmp, _T(","));
}
_sntprintf(tmp + _tcslen(tmp), sizeof tmp, _T("%d"), i);
_sntprintf(tmp + _tcslen(tmp), sizeof tmp + _tcslen(tmp), _T("%d"), i);
}
}
for (int i = 0; i < 8; i++) {
if (p->ecs_genlock_features_plane_mask & (1 << i)) {
if (tmp[0]) {
_tcscat(tmp, _T(","));
}
_sntprintf(tmp + _tcslen(tmp), sizeof tmp, _T("p%d"), i);
_sntprintf(tmp + _tcslen(tmp), sizeof tmp + _tcslen(tmp), _T("p%d"), i);
}
}
cfgfile_dwrite_str(f, _T("genlock_effects"), tmp);
Expand Down Expand Up @@ -2889,7 +2889,7 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type)
if (rbc->monitor_id) {
if (tmp2[0])
_tcscat(tmp2, _T(","));
_sntprintf(tmp2 + _tcslen(tmp2), sizeof tmp2, _T("monitor=%d"), rbc->monitor_id);
_sntprintf(tmp2 + _tcslen(tmp2), sizeof tmp2 + _tcslen(tmp2), _T("monitor=%d"), rbc->monitor_id);
}
if (tmp2[0]) {
if (i > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ uaecptr dumpmem2 (uaecptr addr, TCHAR *out, int osize)
if (debug_safe_addr (addr, 1)) {
b1 = get_byte_debug (addr + 0);
b2 = get_byte_debug (addr + 1);
_sntprintf (out + 9 + i * 5, sizeof out, _T("%02X%02X "), b1, b2);
_sntprintf (out + 9 + i * 5, sizeof out + 9 + i * 5, _T("%02X%02X "), b1, b2);
out[9 + cols * 5 + 1 + i * 2 + 0] = b1 >= 32 && b1 < 127 ? b1 : '.';
out[9 + cols * 5 + 1 + i * 2 + 1] = b2 >= 32 && b2 < 127 ? b2 : '.';
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static void showea_val(TCHAR *buffer, uae_u16 opcode, uaecptr addr, int size)
for (int i = 0; i < size; i++) {
TCHAR name[256];
if (debugmem_get_symbol(addr + i, name, sizeof(name) / sizeof(TCHAR))) {
_sntprintf(buffer + _tcslen(buffer), sizeof buffer, _T(" %s"), name);
_sntprintf(buffer + _tcslen(buffer), sizeof buffer + _tcslen(buffer), _T(" %s"), name);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8346,7 +8346,7 @@ static void dumprdbblock(const uae_u8 *buf, int block)
TCHAR outbuf[81];
for (int j = 0; j < w; j++) {
uae_u8 v = buf[i + j];
_sntprintf(outbuf + 2 * j, sizeof outbuf, _T("%02X"), v);
_sntprintf(outbuf + 2 * j, sizeof outbuf + 2 * j, _T("%02X"), v);
outbuf[2 * w + 1 + j] = (v >= 32 && v <= 126) ? v : '.';
}
outbuf[2 * w] = ' ';
Expand Down
4 changes: 2 additions & 2 deletions src/ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct ini_data *ini_load(const TCHAR *path, bool sort)
struct ini_line *il = ini.inidata[c];
if (il && !_tcscmp(il->section, section)) {
section_id++;
_sntprintf(section + _tcslen(section), sizeof section, _T("|%d"), section_id);
_sntprintf(section + _tcslen(section), sizeof section + _tcslen(section), _T("|%d"), section_id);
break;
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ bool ini_nextsection(struct ini_data *ini, TCHAR *section)
const TCHAR *s = _tcschr(nextsect, '|');
if (s) {
int sectionid = _tstol(s + 1);
_sntprintf(nextsect + (s - nextsect) + 1, sizeof nextsect, _T("%d"), sectionid + 1);
_sntprintf(nextsect + (s - nextsect) + 1, sizeof nextsect + (s - nextsect) + 1, _T("%d"), sectionid + 1);
} else {
_tcscpy(nextsect + _tcslen(nextsect), _T("|2"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/isofs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ static int get_acorn_filename(struct iso_directory_record *de, char *retname, st
*retname = '!';
if (((de->flags[0] & 2) == 0) && (chr[13] == 0xff) && ((chr[12] & 0xf0) == 0xf0)) {
retname[retnamlen] = ',';
_sntprintf(retname+retnamlen+1, sizeof retname, "%3.3x",
_sntprintf(retname+retnamlen+1, sizeof retname+retnamlen+1, "%3.3x",
((chr[12] & 0xf) << 8) | chr[11]);
retnamlen += 4;
}
Expand Down
8 changes: 3 additions & 5 deletions src/osdep/amiberry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,16 @@ void addromfiles(UAEREG* fkey, gcn::DropDown* d, const TCHAR* path, int type1, i
}
}

auto listmodel = d->getListModel(); //xSendDlgItemMessage(hDlg, d, CB_RESETCONTENT, 0, 0);
auto listmodel = d->getListModel();
listmodel->clear();
listmodel->add(""); //xSendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM)_T(""));
listmodel->add("");
for (int i = 0; i < ridx; i++) {
struct romdataentry* rdep = &rde[i];
listmodel->add(rdep->name); //xSendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM)rdep->name);
listmodel->add(rdep->name);
xfree(rdep->name);
}
if (seltmp[0])
{
//xSendDlgItemMessage(hDlg, d, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)seltmp);
for (int i = 0; i < listmodel->getNumberOfElements(); i++) {
if (!_tcsicmp(listmodel->getElementAt(i).c_str(), seltmp)) {
d->setSelected(i);
Expand All @@ -217,7 +216,6 @@ void addromfiles(UAEREG* fkey, gcn::DropDown* d, const TCHAR* path, int type1, i
}
else
{
//SetDlgItemText(hDlg, d, path);
if (path && path[0])
{
listmodel->add(path);
Expand Down
2 changes: 1 addition & 1 deletion src/osdep/gui/PanelExpansions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static void init_expansion2(bool init)
if (cnt == 1)
_tcscat(name, _T("* "));
else if (cnt > 1)
_sntprintf(name + _tcslen(name), sizeof name, _T("[%d] "), cnt);
_sntprintf(name + _tcslen(name), sizeof name + _tcslen(name), _T("[%d] "), cnt);
_tcscat(name, expansionroms[id].friendlyname);
_tcscat(cname, expansionroms[id].friendlyname);
if (expansionroms[id].friendlymanufacturer) {
Expand Down
3 changes: 1 addition & 2 deletions src/osdep/gui/PanelROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ void handleROMSelection(const gcn::ActionEvent& actionEvent, char* prefs)

static void getromfile(gcn::DropDown* d, TCHAR* path, int size)
{
auto val = d->getSelected(); //LRESULT val = xSendDlgItemMessage(hDlg, d, CB_GETCURSEL, 0, 0L);
auto val = d->getSelected();
if (val == -1) {
//xSendDlgItemMessage(hDlg, d, WM_GETTEXT, (WPARAM)size, (LPARAM)path);
auto listmodel = d->getListModel();
listmodel->add(path);
val = listmodel->getNumberOfElements() - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/osdep/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int regsetdata(UAEREG* root, const TCHAR* name, const void* str, int size)
const auto in = (uae_u8*)str;
TCHAR* tmp = xmalloc(TCHAR, size * 2 + 1);
for (int i = 0; i < size; i++)
_sntprintf(tmp + i * 2, sizeof tmp, _T("%02X"), in[i]);
_sntprintf(tmp + i * 2, sizeof tmp + i * 2, _T("%02X"), in[i]);
const int ret = ini_addstring(inidata, gs(root), name, tmp);
xfree(tmp);
return ret;
Expand Down
10 changes: 5 additions & 5 deletions src/rommgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,11 +1765,11 @@ void getromname (const struct romdata *rd, TCHAR *name)
rd--;
_tcscat (name, rd->name);
if ((rd->subrev || rd->subver) && rd->subver != rd->ver)
_sntprintf (name + _tcslen (name), sizeof name, _T(" rev %d.%d"), rd->subver, rd->subrev);
_sntprintf (name + _tcslen (name), sizeof name + _tcslen (name), _T(" rev %d.%d"), rd->subver, rd->subrev);
if (rd->size > 0)
_sntprintf (name + _tcslen (name), sizeof name, _T(" (%dk)"), (rd->size + 1023) / 1024);
_sntprintf (name + _tcslen (name), sizeof name + _tcslen (name), _T(" (%dk)"), (rd->size + 1023) / 1024);
if (rd->partnumber && rd->partnumber[0] != '\0')
_sntprintf (name + _tcslen (name), sizeof name, _T(" [%s]"), rd->partnumber);
_sntprintf (name + _tcslen (name), sizeof name + _tcslen (name), _T(" [%s]"), rd->partnumber);
}

struct romlist *getromlistbyromdata (const struct romdata *rd)
Expand Down Expand Up @@ -2435,13 +2435,13 @@ int configure_rom (struct uae_prefs *p, const int *rom, int msg)

if (rd->type & (ROMTYPE_ARCADIAGAME | ROMTYPE_ALG)) {
get_nvram_path(p->flashfile, sizeof(p->flashfile) / sizeof(TCHAR));
_sntprintf(p->flashfile + _tcslen(p->flashfile), sizeof p->flashfile, _T("%s.nvr"), rd->name);
_sntprintf(p->flashfile + _tcslen(p->flashfile), sizeof p->flashfile + _tcslen(p->flashfile), _T("%s.nvr"), rd->name);
clean_path(p->flashfile);
}
#ifdef ARCADIA
if (rd->type & ROMTYPE_ALG) {
get_video_path(p->genlock_video_file, sizeof(p->genlock_video_file) / sizeof(TCHAR));
_sntprintf(p->genlock_video_file + _tcslen(p->genlock_video_file), sizeof p->genlock_video_file, _T("%s.avi"), rd->name);
_sntprintf(p->genlock_video_file + _tcslen(p->genlock_video_file), sizeof p->genlock_video_file + _tcslen(p->genlock_video_file), _T("%s.avi"), rd->name);
clean_path(p->genlock_video_file);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/savestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ void savestate_quick(int slot, int save)
}
_tcscpy (savestate_fname + i, _T(".uss"));
if (slot > 0) {
_sntprintf (savestate_fname + i, sizeof savestate_fname, _T("_%d.uss"), slot);
_sntprintf (savestate_fname + i, sizeof savestate_fname + i, _T("_%d.uss"), slot);
}
savestate_flags = 0;
if (save) {
Expand Down

0 comments on commit f706383

Please sign in to comment.