summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2024-01-21 11:19:34 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-01-21 13:57:28 -0800
commit1d8fbc4184089beaded2fc1d7bf8bbd23d3e923a (patch)
tree5f4677e9cd4e70b43db650fc8eb05c2df4c0685e
parent283787c9fbeef6cb7c452847a52ecc7f14b6af4a (diff)
Replace sprintf calls with snprintf or XtAsprintf
Raises minimum libXt requirement to 1.1.0 for XtAsprintf Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--command.c4
-rw-r--r--configure.ac2
-rw-r--r--folder.c29
-rw-r--r--init.c10
-rw-r--r--msg.c39
-rw-r--r--pick.c6
-rw-r--r--popup.c12
-rw-r--r--screen.c2
-rw-r--r--toc.c48
-rw-r--r--tocfuncs.c7
-rw-r--r--tocutil.c27
-rw-r--r--util.c24
-rw-r--r--viewfuncs.c2
13 files changed, 112 insertions, 100 deletions
diff --git a/command.c b/command.c
index 2bf9e78..df44049 100644
--- a/command.c
+++ b/command.c
@@ -70,7 +70,7 @@ static void CheckReadFromPipe(int, char **, int *, Bool);
static void SystemError(char* text)
{
char msg[BUFSIZ];
- sprintf( msg, "%s; errno = %d %s", text, errno,
+ snprintf( msg, sizeof(msg), "%s; errno = %d %s", text, errno,
strerror(errno));
XtWarning( msg );
}
@@ -81,7 +81,7 @@ static void SystemError(char* text)
static char *FullPathOfCommand(char *str)
{
static char result[100];
- (void) sprintf(result, "%s/%s", app_resources.mh_path, str);
+ snprintf(result, sizeof(result), "%s/%s", app_resources.mh_path, str);
return result;
}
diff --git a/configure.ac b/configure.ac
index 078e000..9db1712 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,7 +38,7 @@ XORG_MACROS_VERSION(1.8)
XORG_DEFAULT_OPTIONS
# Checks for pkg-config packages
-PKG_CHECK_MODULES(XMH, xaw7 xmu xt x11 xbitmaps >= 1.1.0)
+PKG_CHECK_MODULES(XMH, xaw7 xmu xt >= 1.1 x11 xbitmaps >= 1.1.0)
PKG_CHECK_MODULES(APPDEFS, xt)
xt_appdefaultdir=`$PKG_CONFIG --variable=appdefaultdir xt`
diff --git a/folder.c b/folder.c
index dcdda95..8080f3a 100644
--- a/folder.c
+++ b/folder.c
@@ -263,7 +263,7 @@ static void CreateFolder(
char *name;
Widget dialog = (Widget) client_data;
Arg args[3];
- char str[300], *label;
+ char *label;
name = XawDialogGetValueString(dialog);
for (i=0 ; name[i] > ' ' ; i++) ;
@@ -272,15 +272,15 @@ static void CreateFolder(
if ((toc) || (i==0) || (name[0]=='/') || ((toc = TocCreateFolder(name))
== NULL)) {
if (toc)
- (void) sprintf(str, "Folder \"%s\" already exists. Try again.",
- name);
+ XtAsprintf(&label, "Folder \"%s\" already exists. Try again.",
+ name);
else if (name[0]=='/')
- (void) sprintf(str, "Please specify folders relative to \"%s\".",
- app_resources.mail_path);
+ XtAsprintf(&label, "Please specify folders relative to \"%s\".",
+ app_resources.mail_path);
else
- (void) sprintf(str, "Cannot create folder \"%s\". Try again.",
- name);
- label = XtNewString(str);
+ XtAsprintf(&label, "Cannot create folder \"%s\". Try again.",
+ name);
+
XtSetArg(args[0], XtNlabel, label);
XtSetArg(args[1], XtNvalue, "");
XtSetValues(dialog, args, TWO);
@@ -404,7 +404,8 @@ static void CheckAndConfirmDeleteFolder(
yes_callbacks[0].closure = client_data;
no_callbacks[0].closure = client_data;
- (void) sprintf(str, "Are you sure you want to destroy %s?", TocName(toc));
+ snprintf(str, sizeof(str),
+ "Are you sure you want to destroy %s?", TocName(toc));
PopupConfirm(scrn->tocwidget, str, yes_callbacks, no_callbacks);
}
@@ -566,7 +567,9 @@ static int IsFolder(char *name)
else if (name[0] == '.')
return FALSE;
- (void) sprintf(filename + flen, "/%s", name);
+ if (flen >= sizeof(filename)) return False;
+ if (snprintf(filename + flen, sizeof(filename) - flen, "/%s", name)
+ >= sizeof(filename)) return False;
if (stat(filename, &buf) /* failed */) return False;
#ifdef S_ISDIR
return S_ISDIR(buf.st_mode);
@@ -1056,7 +1059,8 @@ static void CommitMsgInteract(
yes_callbacks[0].closure = no_callbacks[0].closure = (XtPointer) iToken;
- (void)sprintf(str,"Save changes to message %s?", MsgName(scrn->msg));
+ snprintf(str, sizeof(str),
+ "Save changes to message %s?", MsgName(scrn->msg));
/* %%% should add cancel button */
PopupConfirm(scrn->parent, str, yes_callbacks, no_callbacks);
@@ -1129,7 +1133,8 @@ static void CommitTocInteract(
yes_callbacks[0].closure = no_callbacks[0].closure = (XtPointer) iToken;
- (void)sprintf(str,"Commit all changes to %s folder?", toc->foldername);
+ snprintf(str, sizeof(str),
+ "Commit all changes to %s folder?", toc->foldername);
tocwidget = NULL;
for (i=0; i < toc->num_scrns; i++)
diff --git a/init.c b/init.c
index bf84ba0..a1f52a9 100644
--- a/init.c
+++ b/init.c
@@ -430,7 +430,7 @@ void InitializeWorld(int argc, char **argv)
ptr = getenv("MH");
if (!ptr) {
- (void) sprintf(str, "%s/.mh_profile", homeDir);
+ snprintf(str, sizeof(str), "%s/.mh_profile", homeDir);
ptr = str;
}
fid = myfopen(ptr, "r");
@@ -460,12 +460,10 @@ void InitializeWorld(int argc, char **argv)
if (str[0] == '/')
(void) strcpy(str2, str);
else
- (void) sprintf(str2, "%s/%s", homeDir, str);
+ snprintf(str2, sizeof(str2), "%s/%s", homeDir, str);
- (void) sprintf(str, "%s/draft", str2);
- draftFile = XtNewString(str);
- (void) sprintf(str, "%s/xmhdraft", str2);
- xmhDraftFile = XtNewString(str);
+ XtAsprintf(&draftFile, "%s/draft", str2);
+ XtAsprintf(&xmhDraftFile, "%s/xmhdraft", str2);
if (app_resources.mail_path == NULL)
app_resources.mail_path = XtNewString(str2);
diff --git a/msg.c b/msg.c
index 902d224..e4244cd 100644
--- a/msg.c
+++ b/msg.c
@@ -79,7 +79,7 @@ IsEditable(Msg msg)
char *MsgName(Msg msg)
{
static char result[100];
- (void) sprintf(result, "%s:%d", msg->toc->foldername, msg->msgid);
+ snprintf(result, sizeof(result), "%s:%d", msg->toc->foldername, msg->msgid);
return result;
}
@@ -208,7 +208,7 @@ static void RestoreDraft(void)
char *MsgFileName(Msg msg)
{
static char result[500];
- (void) sprintf(result, "%s/%d", msg->toc->path, msg->msgid);
+ snprintf(result, sizeof(result), "%s/%d", msg->toc->path, msg->msgid);
return result;
}
@@ -231,7 +231,7 @@ int MsgSaveChanges(Msg msg)
}
else {
char str[256];
- (void) sprintf(str, "Cannot save changes to \"%s/%d\"!",
+ snprintf(str, sizeof(str), "Cannot save changes to \"%s/%d\"!",
msg->toc->foldername, msg->msgid);
PopupError((Widget)NULL, str);
return False;
@@ -352,9 +352,9 @@ static int SetScrn(
if (msg == NULL || msg->num_scrns == 0) return 0;
if (!force && XawAsciiSourceChanged(msg->source)) {
char str[100];
- (void) sprintf(str,
- "Are you sure you want to remove changes to %s?",
- MsgName(msg));
+ snprintf(str, sizeof(str),
+ "Are you sure you want to remove changes to %s?",
+ MsgName(msg));
yes_callbacks[0].callback = ConfirmedNoScrn;
yes_callbacks[0].closure = (XtPointer) msg;
@@ -385,9 +385,9 @@ static int SetScrn(
cb_data = XtNew(MsgAndScrnRec);
cb_data->msg = msg;
cb_data->scrn = scrn;
- (void)sprintf(str,
- "Are you sure you want to remove changes to %s?",
- MsgName(scrn->msg));
+ snprintf(str, sizeof(str),
+ "Are you sure you want to remove changes to %s?",
+ MsgName(scrn->msg));
yes_callbacks[0].callback = ConfirmedWithScrn;
yes_callbacks[0].closure = (XtPointer) cb_data;
yes_callbacks[1].callback = confirms[0].callback;
@@ -645,7 +645,7 @@ void MsgSend(Msg msg)
(void) MsgSaveChanges(msg);
from = FOpenAndCheck(MsgFileName(msg), "r");
sendcount = (sendcount + 1) % 10;
- (void) sprintf(str, "%s%d", xmhDraftFile, sendcount);
+ snprintf(str, sizeof(str), "%s%d", xmhDraftFile, sendcount);
to = FOpenAndCheck(str, "w");
sendwidth = app_resources.send_line_width;
sendbreakwidth = app_resources.break_send_line_width;
@@ -776,7 +776,7 @@ void MsgLoadReply(
argv = MakeArgv(5 + num_params);
argv[0] = "repl";
argv[1] = TocMakeFolderName(frommsg->toc);
- (void) sprintf(str, "%d", frommsg->msgid);
+ snprintf(str, sizeof(str), "%d", frommsg->msgid);
argv[2] = str;
argv[3] = "-nowhatnowproc";
argv[4] = "-nodraftfolder";
@@ -814,7 +814,7 @@ void MsgLoadForward(
argv[0] = "forw";
argv[1] = TocMakeFolderName(mlist->msglist[0]->toc);
for (i = 0; i < mlist->nummsgs; i++) {
- (void) sprintf(str, "%d", mlist->msglist[i]->msgid);
+ snprintf(str, sizeof(str), "%d", mlist->msglist[i]->msgid);
argv[2 + i] = XtNewString(str);
}
argv[2 + i] = "-nowhatnowproc";
@@ -856,17 +856,18 @@ void MsgCheckPoint(Msg msg)
return;
if (*app_resources.checkpoint_name_format == '/') {
- (void) sprintf(file, app_resources.checkpoint_name_format, msg->msgid);
+ snprintf(file, sizeof(file),
+ app_resources.checkpoint_name_format, msg->msgid);
} else {
- (void) sprintf(file, "%s/", msg->toc->path);
+ snprintf(file, sizeof(file), "%s/", msg->toc->path);
len = strlen(file);
- (void) sprintf(file + len, app_resources.checkpoint_name_format,
- msg->msgid);
+ snprintf(file + len, sizeof(file) - len,
+ app_resources.checkpoint_name_format, msg->msgid);
}
if (!XawAsciiSaveAsFile(msg->source, file)) {
char str[256];
- (void) sprintf(str, "Unsaved edits cannot be checkpointed to %s.",
- file);
+ snprintf(str, sizeof(str),
+ "Unsaved edits cannot be checkpointed to %s.",file);
PopupError((Widget)NULL, str);
}
TocSetCacheValid(msg->toc);
@@ -901,7 +902,7 @@ void XmhInsert(
char *argv[4];
argv[0] = "/bin/sh";
argv[1] = "-c";
- sprintf(command, "%s %s", app_resources.insert_filter,
+ snprintf(command, sizeof(command), "%s %s", app_resources.insert_filter,
MsgFileName(scrn->assocmsg));
argv[2] = command;
argv[3] = NULL;
diff --git a/pick.c b/pick.c
index d0a6ad8..1f4bae6 100644
--- a/pick.c
+++ b/pick.c
@@ -310,7 +310,7 @@ static Boolean ParseRow(RowList row)
case RTother:
XtSetArg(args[0], XtNstring, &other);
XtGetValues(row->wlist[2]->widget, args, (Cardinal) 1);
- (void) sprintf(str, "--%s", other);
+ snprintf(str, sizeof(str), "--%s", other);
AppendArgv(str);
break;
}
@@ -379,7 +379,7 @@ static void ExecOK(
XtGetValues(row0->wlist[3]->widget, args, (Cardinal) 1);
if (TocGetSeqNamed(toc, fromseq) == NULL) {
char str[200];
- (void) sprintf(str, "Sequence \"%s\" doesn't exist!", fromseq);
+ snprintf(str, sizeof(str), "Sequence \"%s\" doesn't exist!", fromseq);
PopupError(pick->scrn->parent, str);
return;
}
@@ -747,7 +747,7 @@ void AddPick(Scrn scrn, Toc toc, char *fromseq, char *toseq)
}
pick->toc = toc;
InitGeneral(pick, fromseq, toseq);
- (void) sprintf(str, "Pick: %s", TocName(toc));
+ snprintf(str, sizeof(str), "Pick: %s", TocName(toc));
ChangeLabel(pick->label, str);
StoreWindowName(scrn, str);
}
diff --git a/popup.c b/popup.c
index 354482d..9053cb2 100644
--- a/popup.c
+++ b/popup.c
@@ -348,13 +348,13 @@ void PopupNotice(
if (l && command[--l] == ':')
command[l] = '\0';
}
- (void) sprintf( label, "%.64s command returned:", command );
+ snprintf(label, sizeof(label), "%.64s command returned:", command);
} else {
/* arbitrary shell command */
int len = strlen(popup_status->shell_command);
- (void) sprintf(label, "%.88s %s\nshell command returned:",
- popup_status->shell_command,
- ((len > 88) ? "[truncated]" : ""));
+ snprintf(label, sizeof(label), "%.88s %s\nshell command returned:",
+ popup_status->shell_command,
+ ((len > 88) ? "[truncated]" : ""));
}
DeterminePopupPosition(&x, &y, &transientFor);
@@ -497,8 +497,8 @@ void PopupWarningHandler(
bzero( &par[i], (10-i) * sizeof(String));
if (*num > 10)
par[9] = "(truncated)";
- (void) sprintf(message, buffer, par[0], par[1], par[2], par[3],
- par[4], par[5], par[6], par[7], par[8], par[9]);
+ snprintf(message, sizeof(message), buffer, par[0], par[1], par[2],
+ par[3], par[4], par[5], par[6], par[7], par[8], par[9]);
ptr = message;
} else {
ptr = buffer;
diff --git a/screen.c b/screen.c
index f27fe15..9f6d6fc 100644
--- a/screen.c
+++ b/screen.c
@@ -244,7 +244,7 @@ static void MakeTocAndView(Scrn scrn)
if (app_resources.command_button_count > 500)
app_resources.command_button_count = 500;
for (i=1; i <= app_resources.command_button_count; i++) {
- sprintf(name, "button%d", i);
+ snprintf(name, sizeof(name), "button%d", i);
BBoxAddButton(scrn->miscbuttons, name, commandWidgetClass, True);
}
}
diff --git a/toc.c b/toc.c
index 708fb1a..860186a 100644
--- a/toc.c
+++ b/toc.c
@@ -41,7 +41,8 @@ static int IsDir(char *name)
struct stat buf;
if (*name == '.')
return FALSE;
- (void) sprintf(str, "%s/%s", app_resources.mail_path, name);
+ if (snprintf(str, sizeof(str), "%s/%s", app_resources.mail_path, name)
+ >= sizeof(str)) return False;
if (stat(str, &buf) /* failed */) return False;
#ifdef S_ISDIR
return S_ISDIR(buf.st_mode);
@@ -60,11 +61,13 @@ static void MakeSureFolderExists(
char str[200];
for (i=0 ; i<*numfoldersptr ; i++)
if (strcmp((*namelistptr)[i], name) == 0) return;
- (void) sprintf(str, "%s/%s", app_resources.mail_path, name);
+ if (snprintf(str, sizeof(str), "%s/%s", app_resources.mail_path, name)
+ >= sizeof(str)) goto punt;
(void) mkdir(str, 0700);
*numfoldersptr = ScanDir(app_resources.mail_path, namelistptr, IsDir);
for (i=0 ; i<*numfoldersptr ; i++)
if (strcmp((*namelistptr)[i], name) == 0) return;
+ punt:
Punt("Can't create new mail folder!");
}
@@ -88,7 +91,9 @@ static void MakeSureSubfolderExists(
/* The parent folder exists. Make sure the subfolder exists. */
- (void) sprintf(subfolder_path, "%s/%s", app_resources.mail_path, name);
+ if (snprintf(subfolder_path, sizeof(subfolder_path), "%s/%s",
+ app_resources.mail_path, name) >= sizeof(subfolder_path))
+ goto punt;
if (stat(subfolder_path, &buf) /* failed */) {
(void) mkdir(subfolder_path, 0700);
if (stat(subfolder_path, &buf) /* failed */)
@@ -99,6 +104,7 @@ static void MakeSureSubfolderExists(
#else
if ((buf.st_mode & S_IFMT) != S_IFDIR)
#endif
+ punt:
Punt("Can't create new xmh subfolder!");
}
@@ -106,9 +112,8 @@ int TocFolderExists(Toc toc)
{
struct stat buf;
if (! toc->path) {
- char str[500];
- (void) sprintf(str, "%s/%s", app_resources.mail_path, toc->foldername);
- toc->path = XtNewString(str);
+ XtAsprintf(&toc->path, "%s/%s",
+ app_resources.mail_path, toc->foldername);
}
return ((stat(toc->path, &buf) == 0) &&
#ifdef S_ISDIR
@@ -123,7 +128,7 @@ static void LoadCheckFiles(void)
FILE *fid;
char str[1024];
- (void) sprintf(str, "%s/.xmhcheck", homeDir);
+ snprintf(str, sizeof(str), "%s/.xmhcheck", homeDir);
fid = myfopen(str, "r");
if (fid) {
int i;
@@ -219,7 +224,8 @@ Toc TocCreateFolder(char *foldername)
Toc toc;
char str[500];
if (TocGetNamed(foldername)) return NULL;
- (void) sprintf(str, "%s/%s", app_resources.mail_path, foldername);
+ if (snprintf(str, sizeof(str), "%s/%s", app_resources.mail_path, foldername)
+ >= sizeof(str)) return NULL;
if (mkdir(str, 0700) < 0) return NULL;
toc = TocCreate(foldername);
return toc;
@@ -797,8 +803,8 @@ void TocSetCacheValid(Toc toc)
char *TocMakeFolderName(Toc toc)
{
- char* name = XtMalloc((Cardinal) (strlen(toc->path) + 2) );
- (void)sprintf( name, "+%s", toc->path );
+ char* name;
+ XtAsprintf(&name, "+%s", toc->path);
return name;
}
@@ -872,8 +878,9 @@ int TocConfirmCataclysm(
char str[300];
Widget tocwidget;
- (void)sprintf(str,"Are you sure you want to remove all changes to %s?",
- toc->foldername);
+ snprintf(str, sizeof(str),
+ "Are you sure you want to remove all changes to %s?",
+ toc->foldername);
yes_callbacks[0].closure = (XtPointer) toc;
yes_callbacks[1].callback = confirms[0].callback;
yes_callbacks[1].closure = confirms[0].closure;
@@ -967,7 +974,7 @@ void TocCommitChanges(
if (curfate != Fignore &&
curfate == fate && desttoc == curdesttoc) {
argv = ResizeArgv(argv, cur + 1);
- (void) sprintf(str, "%d", MsgGetId(msg));
+ snprintf(str, sizeof(str), "%d", MsgGetId(msg));
argv[cur++] = XtNewString(str);
MsgSetFate(msg, Fignore, (Toc)NULL);
if (curdesttoc) {
@@ -1044,7 +1051,7 @@ int TocIncorporate(Toc toc)
argv[0] = "inc";
argv[1] = TocMakeFolderName(toc);
argv[2] = "-width";
- (void) sprintf(str, "%d", app_resources.toc_width);
+ snprintf(str, sizeof(str), "%d", app_resources.toc_width);
argv[3] = str;
if (toc->incfile) {
argv[4] = "-file";
@@ -1097,10 +1104,10 @@ void TocMsgChanged(Toc toc, Msg msg)
argv = MakeArgv(6);
argv[0] = "scan";
argv[1] = TocMakeFolderName(toc);
- (void) sprintf(str, "%d", msg->msgid);
+ snprintf(str, sizeof(str), "%d", msg->msgid);
argv[2] = str;
argv[3] = "-width";
- (void) sprintf(str2, "%d", app_resources.toc_width);
+ snprintf(str2, sizeof(str2), "%d", app_resources.toc_width);
argv[4] = str2;
argv[5] = "-noheader";
ptr = DoCommandToString(argv);
@@ -1137,7 +1144,8 @@ Msg TocMsgFromId(Toc toc, int msgid)
if (h < 0) {
if (app_resources.debug) {
char str[100];
- (void)sprintf(str, "Toc is empty! folder=%s\n", toc->foldername);
+ snprintf(str, sizeof(str),
+ "Toc is empty! folder=%s\n", toc->foldername);
DEBUG( str )
}
return NULL;
@@ -1153,9 +1161,9 @@ Msg TocMsgFromId(Toc toc, int msgid)
if (toc->msgs[h]->msgid == msgid) return toc->msgs[h];
if (app_resources.debug) {
char str[100];
- (void) sprintf(str,
- "TocMsgFromId search failed! hi=%d, lo=%d, msgid=%d\n",
- h, l, msgid);
+ snprintf(str, sizeof(str),
+ "TocMsgFromId search failed! hi=%d, lo=%d, msgid=%d\n",
+ h, l, msgid);
DEBUG( str )
}
return NULL;
diff --git a/tocfuncs.c b/tocfuncs.c
index 43134c3..f07d5c4 100644
--- a/tocfuncs.c
+++ b/tocfuncs.c
@@ -938,7 +938,7 @@ typedef enum {ADD, REMOVE, DELETE} TwiddleOperation;
static void TwiddleSequence(Scrn scrn, TwiddleOperation op)
{
Toc toc = scrn->toc;
- char **argv, str[100];
+ char **argv;
int i;
MsgList mlist;
Sequence selectedseq;
@@ -979,8 +979,9 @@ static void TwiddleSequence(Scrn scrn, TwiddleOperation op)
break;
}
for (i = 0; i < mlist->nummsgs; i++) {
- (void) sprintf(str, "%d", MsgGetId(mlist->msglist[i]));
- argv[6 + i] = XtNewString(str);
+ char *str;
+ XtAsprintf(&str, "%d", MsgGetId(mlist->msglist[i]));
+ argv[6 + i] = str;
}
DoCommand(argv, (char *) NULL, (char *) NULL);
for (i = 0; i < mlist->nummsgs; i++)
diff --git a/tocutil.c b/tocutil.c
index 14fc82c..d9e84bb 100644
--- a/tocutil.c
+++ b/tocutil.c
@@ -135,14 +135,14 @@ void TUScanFileForToc(Toc toc)
if (toc->num_scrns) scrn = toc->scrn[0];
else scrn = scrnList[0];
- (void) sprintf(str, "Rescanning %s", toc->foldername);
+ snprintf(str, sizeof(str), "Rescanning %s", toc->foldername);
ChangeLabel(scrn->toclabel, str);
argv = MakeArgv(5);
argv[0] = "scan";
argv[1] = TocMakeFolderName(toc);
argv[2] = "-width";
- (void) sprintf(str, "%d", app_resources.toc_width);
+ snprintf(str, sizeof(str), "%d", app_resources.toc_width);
argv[3] = str;
argv[4] = "-noheader";
DoCommand(argv, (char *) NULL, toc->scanfile);
@@ -180,9 +180,9 @@ int TUGetMsgPosition(Toc toc, Msg msg)
for (l = 0; l < toc->nummsgs; l++) {
if (msgid == toc->msgs[l]->msgid) return l;
}
- (void) sprintf(str,
- "TUGetMsgPosition search failed! hi=%d, lo=%d, msgid=%d",
- h, l, msgid);
+ snprintf(str, sizeof(str),
+ "TUGetMsgPosition search failed! hi=%d, lo=%d, msgid=%d",
+ h, l, msgid);
Punt(str);
return 0; /* Keep lint happy. */
}
@@ -201,8 +201,8 @@ void TUResetTocLabel(Scrn scrn)
toc->needslabelupdate = TRUE;
return;
}
- (void) sprintf(str, "%s:%s", toc->foldername,
- toc->viewedseq->name);
+ snprintf(str, sizeof(str), "%s:%s", toc->foldername,
+ toc->viewedseq->name);
toc->needslabelupdate = FALSE;
}
ChangeLabel((Widget) scrn->toclabel, str);
@@ -266,7 +266,7 @@ void TULoadSeqLists(Toc toc)
seq->mlist = NULL;
toc->viewedseq = seq;
toc->selectseq = seq;
- (void) sprintf(str, "%s/.mh_sequences", toc->path);
+ snprintf(str, sizeof(str), "%s/.mh_sequences", toc->path);
fid = myfopen(str, "r");
if (fid) {
while ((ptr = ReadLine(fid))) {
@@ -573,16 +573,13 @@ void TURefigureTocPositions(Toc toc)
void TUGetFullFolderInfo(Toc toc)
{
- char str[500];
if (! toc->scanfile) {
if (! toc->path) {
/* usually preset by TocFolderExists */
- (void) sprintf(str, "%s/%s", app_resources.mail_path,
- toc->foldername);
- toc->path = XtNewString(str);
+ XtAsprintf(&toc->path, "%s/%s", app_resources.mail_path,
+ toc->foldername);
}
- (void) sprintf(str, "%s/.xmhcache", toc->path);
- toc->scanfile = XtNewString(str);
+ XtAsprintf(&toc->scanfile, "%s/.xmhcache", toc->path);
toc->lastreaddate = LastModifyDate(toc->scanfile);
if (TUScanFileOutOfDate(toc))
toc->validity = invalid;
@@ -619,7 +616,7 @@ Msg TUAppendToc(Toc toc, char *ptr)
msg->buf = XtNewString(ptr);
if (msgid >= 10000)
msgid %= 10000;
- (void)sprintf(msg->buf, "%4d", msgid);
+ snprintf(msg->buf, strlen(msg->buf) + 1, "%4d", msgid);
msg->buf[MARKPOS] = ' ';
msg->msgid = msgid;
msg->position = toc->lastPos;
diff --git a/util.c b/util.c
index 2d3aca1..26b73db 100644
--- a/util.c
+++ b/util.c
@@ -107,8 +107,8 @@ char *MakeNewTempFileName(void)
static char name[60];
static int uniqueid = 0;
do {
- (void) sprintf(name, "%s/xmh_%ld_%d", app_resources.temp_dir,
- (long)getpid(), uniqueid++);
+ snprintf(name, sizeof(name), "%s/xmh_%ld_%d", app_resources.temp_dir,
+ (long)getpid(), uniqueid++);
} while (FileExists(name));
return name;
}
@@ -141,7 +141,7 @@ FILEPTR FOpenAndCheck(char *name, char *mode)
if (result == NULL) {
char str[500];
perror(progName);
- (void)sprintf(str, "Error in FOpenAndCheck(%s, %s)", name, mode);
+ snprintf(str, sizeof(str), "Error in FOpenAndCheck(%s, %s)", name, mode);
Punt(str);
}
return result;
@@ -200,7 +200,7 @@ void DeleteFileAndCheck(char *name)
if (strcmp(name, "/dev/null") != 0 && unlink(name) == -1) {
char str[500];
perror(progName);
- (void)sprintf(str, "DeleteFileAndCheck(%s) failed!", name);
+ snprintf(str, sizeof(str), "DeleteFileAndCheck(%s) failed!", name);
Punt(str);
}
}
@@ -213,7 +213,7 @@ void CopyFileAndCheck(char *from, char *to)
tofid = myopen(to, O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (fromfid < 0 || tofid < 0) {
perror(progName);
- (void)sprintf(buf, "CopyFileAndCheck(%s->%s) failed!", from, to);
+ snprintf(buf, sizeof(buf), "CopyFileAndCheck(%s->%s) failed!", from, to);
Punt(buf);
}
do {
@@ -231,7 +231,7 @@ void RenameAndCheck(char *from, char *to)
if (errno != EXDEV) {
char str[500];
perror(progName);
- (void)sprintf(str, "RenameAndCheck(%s->%s) failed!", from, to);
+ snprintf(str, sizeof(str), "RenameAndCheck(%s->%s) failed!", from, to);
Punt(str);
}
CopyFileAndCheck(from, to);
@@ -244,23 +244,25 @@ char *CreateGeometry(int gbits, int x, int y, int width, int height)
{
char *result, str1[10], str2[10], str3[10], str4[10];
if (gbits & WidthValue)
- (void) sprintf(str1, "=%d", width);
+ snprintf(str1, sizeof(str1), "=%d", width);
else
(void) strcpy(str1, "=");
if (gbits & HeightValue)
- (void) sprintf(str2, "x%d", height);
+ snprintf(str2, sizeof(str2), "x%d", height);
else
(void) strcpy(str2, "x");
if (gbits & XValue)
- (void) sprintf(str3, "%c%d", (gbits & XNegative) ? '-' : '+', abs(x));
+ snprintf(str3, sizeof(str3),
+ "%c%d", (gbits & XNegative) ? '-' : '+', abs(x));
else
(void) strcpy(str3, "");
if (gbits & YValue)
- (void) sprintf(str4, "%c%d", (gbits & YNegative) ? '-' : '+', abs(y));
+ snprintf(str4, sizeof(str4),
+ "%c%d", (gbits & YNegative) ? '-' : '+', abs(y));
else
(void) strcpy(str4, "");
result = XtMalloc((unsigned) 22);
- (void) sprintf(result, "%s%s%s%s", str1, str2, str3, str4);
+ snprintf(result, 22, "%s%s%s%s", str1, str2, str3, str4);
return result;
}
diff --git a/viewfuncs.c b/viewfuncs.c
index ac2a924..f9a4dea 100644
--- a/viewfuncs.c
+++ b/viewfuncs.c
@@ -247,7 +247,7 @@ void DoPrintView(
char str[200];
if (! scrn->msg) return;
- (void) sprintf(str, "%s %s", app_resources.print_command,
+ snprintf(str, sizeof(str), "%s %s", app_resources.print_command,
MsgFileName(scrn->msg));
argv = MakeArgv(3);
argv[0] = "/bin/sh";