Only allocate memory if needed

pull/4/head
Moritz Luedecke 7 years ago
parent 72044dca8a
commit 9241e51a81

@ -152,7 +152,7 @@ drawwin(void) {
size_t asterlen = strlen(asterisk); size_t asterlen = strlen(asterisk);
size_t pdesclen; size_t pdesclen;
int leftinput; int leftinput;
char* censort = ecalloc(1, asterlen * pinentry->pin_len); char* censort;
unsigned int censortl = minpwlen * TEXTW(asterisk) / strlen(asterisk); unsigned int censortl = minpwlen * TEXTW(asterisk) / strlen(asterisk);
unsigned int confirml = TEXTW(" YesNo ") + 3 * lrpad; unsigned int confirml = TEXTW(" YesNo ") + 3 * lrpad;
@ -204,6 +204,8 @@ drawwin(void) {
drw_setscheme(drw, scheme[SchemeNormal]); drw_setscheme(drw, scheme[SchemeNormal]);
if (winmode == WinPin) { if (winmode == WinPin) {
censort = ecalloc(1, asterlen * pinentry->pin_len);
for (i = 0; i < asterlen * strlen(pin); i += asterlen) { for (i = 0; i < asterlen * strlen(pin); i += asterlen) {
memcpy(&censort[i], asterisk, asterlen); memcpy(&censort[i], asterisk, asterlen);
} }
@ -217,13 +219,14 @@ drawwin(void) {
drw_setscheme(drw, scheme[SchemeNormal]); drw_setscheme(drw, scheme[SchemeNormal]);
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
} }
free(censort);
} else { } else {
x += TEXTW(" "); x += TEXTW(" ");
x = drawitem("No", (sel == No), x, 0, TEXTW("No")); x = drawitem("No", (sel == No), x, 0, TEXTW("No"));
x = drawitem("Yes", (sel == Yes), x, 0, TEXTW("Yes")); x = drawitem("Yes", (sel == Yes), x, 0, TEXTW("Yes"));
} }
free(censort);
drw_map(drw, win, 0, 0, mw, mh); drw_map(drw, win, 0, 0, mw, mh);
} }

Loading…
Cancel
Save