Skip to content

Commit f2837df

Browse files
authored
Merge pull request #214 from edgar-bonet/no-fpe
Avoid division by zero on small windows
2 parents ea84bb2 + c4e21c6 commit f2837df

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ttyplot.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
#define T_LLCR ACS_LLCORNER
5454
#endif
5555

56+
// Window size
57+
#define WIDTH_MIN 68
58+
#define WIDTH_MARGIN 4
59+
#define HEIGHT_MIN 5
60+
#define HEIGHT_MARGIN 4
61+
5662
// Define standard curses color constants for better readability
5763
#define C_BLACK 0
5864
#define C_RED 1
@@ -91,7 +97,7 @@ static double softmax = 0.0, hardmax = FLT_MAX, softmin = 0.0, hardmin = -FLT_MA
9197
static char title[256] = ".: ttyplot :.", unit[64] = {0}, ls[256] = {0};
9298
static double values1[1024] = {0}, values2[1024] = {0};
9399
static int width = 0, height = 0, n = -1, v = 0, c = 0, rate = 0, two = 0,
94-
plotwidth = 0, plotheight = 0;
100+
plotwidth = WIDTH_MIN - WIDTH_MARGIN, plotheight = 0;
95101
static bool fake_clock = false;
96102
static char *errstr = NULL;
97103
static bool redraw_needed = false;
@@ -485,7 +491,7 @@ static void show_all_centered(const char *message) {
485491
}
486492

487493
static int window_big_enough_to_draw(void) {
488-
return (width >= 68) && (height >= 5);
494+
return (width >= WIDTH_MIN) && (height >= HEIGHT_MIN);
489495
}
490496

491497
static void show_window_size_error(void) {
@@ -500,8 +506,8 @@ static void paint_plot(void) {
500506
erase();
501507
getmaxyx(stdscr, height, width);
502508

503-
plotheight = height - 4;
504-
plotwidth = width - 4;
509+
plotheight = height - HEIGHT_MARGIN;
510+
plotwidth = width - WIDTH_MARGIN;
505511
if (plotwidth >= (int)((sizeof(values1) / sizeof(double)) - 1))
506512
exit(0);
507513

0 commit comments

Comments
 (0)