1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Use a more robust idiom When converting sprintf() to snprintf()

don't use the idiom

char foo[BUFSIZ];
snprintf(foo, BUFSIZ, ....);

but

char foo[BUFSIZ];
snprintf(foo, sizeo foo, ....);

because this will automatically catch situations where the size of foo
is later changed, e.g. like  foo[BUFSIZ + 8];

Fix another use of sprintf.
This commit is contained in:
Marc Balmer 2012-08-09 07:08:05 +02:00 committed by Jon Trulson
parent 117258766b
commit bb21797684
2 changed files with 2 additions and 2 deletions

View file

@ -898,7 +898,7 @@ GetUserPrompt( void )
XmString cancelLabel;
XmString okLabel;
snprintf(prompt, BUFSIZ, (GETMESSAGE(1,5, "Enter password for user %s:")),
snprintf(prompt, sizeof prompt, (GETMESSAGE(1,5, "Enter password for user %s:")),
appArgs.user);
xmString = XmStringCreateLocalized(prompt);
xmString2 =XmStringCreateLocalized(GETMESSAGE(1,6, "Action Invoker - Password"));

View file

@ -146,7 +146,7 @@ logStartStop(char *progName, int logfd, int start)
/* remove the trailing '\n'... */
tstring[strlen(tstring) - 1] = '\0';
(void) sprintf(buffer, "%s: %s %s\n",
(void) snprintf(buffer, sizeof buffer, "%s: %s %s\n",
(savedProgName && *savedProgName) ? savedProgName : "logger",
start ? "starting" : "terminating",
tstring);