Merge pull request #69 from pnappa/master

Fixed bug where piping into sneakers caused memory corruption
This commit is contained in:
Brian Barto 2019-03-02 15:23:56 -05:00 committed by GitHub
commit 16fcd1e2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;
} }