Skip to content

Commit

Permalink
iio-monitor: fix Argument cannot be negative
Browse files Browse the repository at this point in the history
The function `getmaxyx(win, row, col);` can return negative values if
things are in a subwindow, and then these values are passed to the
function `newwin`, which requires positive values. This sets up a
potential error.

Fix this by setting a min screen size (10 rows x 50 columns) to display
content, and gracefully erroring if the size is too small.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Apr 24, 2020
1 parent b31fc3e commit 973c61c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ int main(void)
noecho();
keypad(win, TRUE);
getmaxyx(win, row, col);

/* If this was started from a small window, quit */
if (row < 10 || col < 50) {
endwin();
fprintf(stderr, "Sorry, I need a bigger window,\n"
"min is 10 x 50\n");
return 0;
}

initCDKColor();

left = newwin(row, col / 2, 0, 0);
Expand Down

0 comments on commit 973c61c

Please sign in to comment.