diff options
author | Nachiketa Prachanda <nchkta@gmail.com> | 2017-01-31 12:08:48 -0800 |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2017-02-02 20:56:59 +0100 |
commit | 341375179514bfd96f2d6001df15a4079631491b (patch) | |
tree | 0c55339e95b733499e7961f440676ed6d22cb76c | |
parent | 1b3f11bde315e221474f7d066ce4efb4ff4d39e3 (diff) |
out_curses: use xcalloc instead of a fixed buffer
In put_line(), replace the fixed onstack buffer with a xcalloc-ed buffer.
This fixes a bmon crash with terminal size larger than 2048 bytes. The crash
be reproduced with
$ stty cols 2100
$ bmon ....
Signed-off-by: Nachiketa Prachanda <nchkta@gmail.com>
-rw-r--r-- | src/out_curses.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/out_curses.c b/src/out_curses.c index 6d70ae3..e5317de 100644 --- a/src/out_curses.c +++ b/src/out_curses.c @@ -147,22 +147,24 @@ static char *float2str(double value, int width, int prec, char *buf, size_t len) static void put_line(const char *fmt, ...) { va_list args; - char buf[2048]; + char *buf; + int len; int x, y __unused__; - memset(buf, 0, sizeof(buf)); getyx(stdscr, y, x); + len = cols - x; + buf = xcalloc(len+1, 1); + va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); + vsnprintf(buf, len+1, fmt, args); va_end(args); - if (strlen(buf) > cols-x) - buf[cols - x] = '\0'; - else - memset(&buf[strlen(buf)], ' ', cols - strlen(buf)-x); + if (strlen(buf) < len) + memset(&buf[strlen(buf)], ' ', len - strlen(buf)); addstr(buf); + xfree(buf); } static void center_text(const char *fmt, ...) |