Replace several uses of snprintf() by asprintf()

Use asprintf() in some cold code paths. While allocating memory on the
heap is a bit slower, using asprintf() is a bit more memory efficient
and less prone to buffer overflow errors.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer
2014-07-21 22:51:54 +02:00
parent 6203966fbf
commit 21fc7a4b74
9 changed files with 150 additions and 135 deletions

View File

@@ -629,7 +629,7 @@ void ui_calendar_change_day(int datefmt)
{
#define LDAY 11
char selected_day[LDAY] = "";
char outstr[BUFSIZ];
char *outstr;
int dday, dmonth, dyear;
int wrong_day = 1;
const char *mesg_line1 =
@@ -640,9 +640,9 @@ void ui_calendar_change_day(int datefmt)
_("Enter the day to go to [ENTER for today] : %s");
while (wrong_day) {
snprintf(outstr, BUFSIZ, request_date,
DATEFMT_DESC(datefmt));
asprintf(&outstr, request_date, DATEFMT_DESC(datefmt));
status_mesg(outstr, "");
mem_free(outstr);
if (getstring(win[STA].p, selected_day, LDAY, 0, 1) ==
GETSTRING_ESC) {
return;