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:
@@ -803,14 +803,15 @@ print_keys_bindings(WINDOW * win, int selected_row, int selected_elm,
|
||||
|
||||
noelm = y = 0;
|
||||
for (action = 0; action < NBKEYS; action++) {
|
||||
char actionstr[BUFSIZ];
|
||||
char *actionstr;
|
||||
int nbkeys;
|
||||
|
||||
nbkeys = keys_action_count_keys(action);
|
||||
snprintf(actionstr, BUFSIZ, "%s", keys_get_label(action));
|
||||
asprintf(&actionstr, "%s", keys_get_label(action));
|
||||
if (action == selected_row)
|
||||
custom_apply_attr(win, ATTR_HIGHEST);
|
||||
mvwprintw(win, y, XPOS, "%s ", actionstr);
|
||||
mem_free(actionstr);
|
||||
mvwaddstr(win, y, EQUALPOS, "=");
|
||||
if (nbkeys == 0)
|
||||
mvwaddstr(win, y, KEYPOS, _("undefined"));
|
||||
|
||||
Reference in New Issue
Block a user