Date: Tue, 03 Sep 2019 14:06:18 -0000 From: Dimitry Andric <dim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r345953 - stable/12/usr.bin/top Message-ID: <201904051612.x35GCWYN085289@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dim Date: Fri Apr 5 16:12:31 2019 New Revision: 345953 URL: https://svnweb.freebsd.org/changeset/base/345953 Log: MFC r345807: Fix regression in top(1) after r344381, causing informational messages to no longer be displayed. This was because the reimplementation of setup_buffer() did not copy the previous contents into any reallocated buffer. Reported by: James Wright <james.wright@jigsawdezign.com> PR: 236947 Modified: stable/12/usr.bin/top/display.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.bin/top/display.c ============================================================================== --- stable/12/usr.bin/top/display.c Fri Apr 5 16:09:23 2019 (r345952) +++ stable/12/usr.bin/top/display.c Fri Apr 5 16:12:31 2019 (r345953) @@ -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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904051612.x35GCWYN085289>