fixed bug where piping into sneakers caused crash, and added missing free

This commit is contained in:
Patrick Nappa 2019-02-13 11:06:42 +11:00
parent 50dc9cc055
commit 90b7d0410b

View File

@ -32,7 +32,11 @@ int main(void) {
// Get terminal dimentions (needed for centering) // Get terminal dimentions (needed for centering)
struct winsize w; struct winsize w;
ioctl(0, TIOCGWINSZ, &w); // if not an interactive tty, w is not populated, resulting in UB
if (ioctl(0, TIOCGWINSZ, &w) == -1) {
perror("Input not from an interactive terminal");
return 1;
}
termCols = w.ws_col; termCols = w.ws_col;
// Allocate space for our display string // Allocate space for our display string
@ -45,6 +49,7 @@ int main(void) {
// Allocate space for our display string // Allocate space for our display string
if ((display_uc = malloc(20 * termCols)) == NULL) if ((display_uc = malloc(20 * termCols)) == NULL)
{ {
free(display);
fprintf(stderr, "Memory Allocation Error. Quitting!\n"); fprintf(stderr, "Memory Allocation Error. Quitting!\n");
return 1; return 1;
} }