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>
This commit is contained in:
parent
1b3f11bde3
commit
3413751795
@ -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, ...)
|
static void put_line(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[2048];
|
char *buf;
|
||||||
|
int len;
|
||||||
int x, y __unused__;
|
int x, y __unused__;
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
getyx(stdscr, y, x);
|
getyx(stdscr, y, x);
|
||||||
|
|
||||||
|
len = cols - x;
|
||||||
|
buf = xcalloc(len+1, 1);
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsnprintf(buf, sizeof(buf), fmt, args);
|
vsnprintf(buf, len+1, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (strlen(buf) > cols-x)
|
if (strlen(buf) < len)
|
||||||
buf[cols - x] = '\0';
|
memset(&buf[strlen(buf)], ' ', len - strlen(buf));
|
||||||
else
|
|
||||||
memset(&buf[strlen(buf)], ' ', cols - strlen(buf)-x);
|
|
||||||
|
|
||||||
addstr(buf);
|
addstr(buf);
|
||||||
|
xfree(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void center_text(const char *fmt, ...)
|
static void center_text(const char *fmt, ...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user