mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.99] Fix a bug that caused segfault when terminal size cannot be retrieved (e.g, redirection)
This commit is contained in:
@@ -34,8 +34,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define max(a,b) (((a)>(b))?(a):(b))
|
|
||||||
#define MAX_ATTRIBUTES 100
|
#define MAX_ATTRIBUTES 100
|
||||||
|
#define MAX_TERM_SIZE 1024
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
||||||
@@ -787,16 +787,20 @@ struct terminal* get_terminal_size() {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
if(GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) == 0) {
|
if(GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) == 0) {
|
||||||
printWarn("GetConsoleScreenBufferInfo failed");
|
printWarn("get_terminal_size: GetConsoleScreenBufferInfo failed");
|
||||||
return NULL;
|
term->w = MAX_TERM_SIZE;
|
||||||
|
term->h = MAX_TERM_SIZE;
|
||||||
|
return term;
|
||||||
}
|
}
|
||||||
term->w = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
term->w = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
||||||
term->h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
term->h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
||||||
#else
|
#else
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
|
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
|
||||||
printErr("ioctl: %s", strerror(errno));
|
printWarn("get_terminal_size: ioctl: %s", strerror(errno));
|
||||||
return NULL;
|
term->w = MAX_TERM_SIZE;
|
||||||
|
term->h = MAX_TERM_SIZE;
|
||||||
|
return term;
|
||||||
}
|
}
|
||||||
term->h = w.ws_row;
|
term->h = w.ws_row;
|
||||||
term->w = w.ws_col;
|
term->w = w.ws_col;
|
||||||
|
|||||||
Reference in New Issue
Block a user