jcs
/amend
/amendments
/133
settings: Center dialog, enforce author min size
jcs made amendment 133 over 2 years ago
--- settings.c Thu May 4 15:58:31 2023
+++ settings.c Thu Jan 11 15:18:09 2024
@@ -94,11 +94,25 @@ settings_edit(void)
{
Str255 txt;
Handle ihandle;
+ size_t len;
short itype, hit;
bool done;
DialogPtr dlg;
+ DialogTHndl dhand;
+ DialogTPtr dp;
Rect irect;
+ dhand = (DialogTHndl)GetResource('DLOG', SETTINGS_DLOG_ID);
+ if (dhand == NULL)
+ panic("No settings dialog");
+ LoadResource((Handle)dhand);
+
+ HLock((Handle)dhand);
+ dp = (DialogTPtr)(*dhand);
+ center_in_screen(dp->boundsRect.right - dp->boundsRect.left,
+ dp->boundsRect.bottom - dp->boundsRect.top, false, &dp->boundsRect);
+ HUnlock((Handle)dhand);
+
dlg = GetNewDialog(SETTINGS_DLOG_ID, nil, (WindowPtr)-1);
if (dlg == NULL)
err(1, "Can't find settings DLOG %d", SETTINGS_DLOG_ID);
@@ -136,13 +150,17 @@ dialog_wait:
GetDItem(dlg, SETTINGS_AUTHOR_ID, &itype, &ihandle, &irect);
GetIText(ihandle, txt);
PtoCstr(txt);
- if (strlen((char *)&txt) >= sizeof(settings.author)) {
+ len = strlen((char *)txt);
+ if (len >= sizeof(settings.author)) {
warn("Author setting is too long (%ld max)",
sizeof(settings.author) - 1);
goto dialog_wait;
+ } else if (len == 0) {
+ warn("Author cannot be blank");
+ goto dialog_wait;
}
- memcpy(settings.author, txt, strlen((char *)&txt) + 1);
+ strlcpy(settings.author, (char *)txt, sizeof(settings.author));
GetDItem(dlg, SETTINGS_TABWIDTH_ID, &itype, &ihandle, &irect);
GetIText(ihandle, txt);