aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/top
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-04-02 18:01:54 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-04-02 18:01:54 +0000
commitc26e2e37aabd65e7581ba4c0a28330469fc685b0 (patch)
treeb1875d4e1992ce2c05b64222badc7204e7ceab37 /usr.bin/top
parentd705ee60a29efec758001781f664dec656e8239e (diff)
downloadsrc-c26e2e37aabd65e7581ba4c0a28330469fc685b0.tar.gz
src-c26e2e37aabd65e7581ba4c0a28330469fc685b0.zip
Notes
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/display.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index 708855fb095f..539ddb4d536e 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -1347,7 +1347,8 @@ i_uptime(struct timeval *bt, time_t *tod)
static char *
setup_buffer(char *buffer, int addlen)
{
- size_t len;
+ size_t len, old_len;
+ char *new_buffer;
setup_buffer_bufsiz = screen_width;
if (setup_buffer_bufsiz < SETUPBUFFER_MIN_SCREENWIDTH)
@@ -1355,13 +1356,18 @@ setup_buffer(char *buffer, int addlen)
setup_buffer_bufsiz = SETUPBUFFER_MIN_SCREENWIDTH;
}
- free(buffer);
len = setup_buffer_bufsiz + addlen + SETUPBUFFER_REQUIRED_ADDBUFSIZ;
- buffer = calloc(len, sizeof(char));
- if (buffer == NULL)
+ new_buffer = calloc(len, sizeof(char));
+ if (new_buffer == NULL)
{
errx(4, "can't allocate sufficient memory");
}
+ if (buffer != NULL)
+ {
+ old_len = strlen(buffer);
+ memcpy(new_buffer, buffer, old_len < len - 1 ? old_len : len - 1);
+ free(buffer);
+ }
- return buffer;
+ return new_buffer;
}