From owner-svn-src-all@freebsd.org Wed Apr 3 19:43:10 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6451515510BA; Wed, 3 Apr 2019 19:43:10 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:470:7a58:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "tensor.andric.com", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F3A7A6A656; Wed, 3 Apr 2019 19:43:09 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:470:7a58::7c78:2711:3f37:8a5d] (unknown [IPv6:2001:470:7a58:0:7c78:2711:3f37:8a5d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id D05CB3F6D0; Wed, 3 Apr 2019 21:42:59 +0200 (CEST) From: Dimitry Andric Message-Id: Content-Type: multipart/signed; boundary="Apple-Mail=_5733E18B-193D-4A27-B386-DDD252477B54"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: Re: svn commit: r345807 - head/usr.bin/top Date: Wed, 3 Apr 2019 21:42:59 +0200 In-Reply-To: <20190403234558.X1970@besplex.bde.org> Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org To: Bruce Evans References: <201904021801.x32I1sxX019439@repo.freebsd.org> <20190403234558.X1970@besplex.bde.org> X-Mailer: Apple Mail (2.3445.104.8) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Apr 2019 19:43:10 -0000 --Apple-Mail=_5733E18B-193D-4A27-B386-DDD252477B54 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii On 3 Apr 2019, at 15:16, Bruce Evans wrote: > > On Tue, 2 Apr 2019, Dimitry Andric wrote: >> Author: dim >> Date: Tue Apr 2 18:01:54 2019 >> New Revision: 345807 >> URL: https://svnweb.freebsd.org/changeset/base/345807 >> >> Log: >> 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. ... > Looks like realloc() hasn't been invented yet. > > realloc() wouldn't clear the new part of the buffer, so a memset() or at > least setting the first byte in a new buffer (starting with buffer == NULL > might be needed). Yeah, I found that a bit ugly, so just using calloc (like the previous implementation of setup_buffer did) and copying only the old contents seemed nicer. I never liked realloc's interface. > The above has some bugs when the new buffer is smaller the old buffer: > - when old_len < len - 1, the new buffer has no space for the old buffer > including its NUL terminator, so the new buffer is left unterminated > after blind truncation No, in this case the old buffer can be copied entirely, and the new buffer will already be NUL terminated, because calloc has filled the entirety of it with zeroes. This is also expected in the rest of the display.c code. > - when old_len == len - 1, the new buffer has no space for the NUL > terminator, so the new buffer is left unterminated after not overrunning > it by copying the NUL terminator No, in this case the old buffer can be copied entirely, and the new buffer will have exactly one zero byte at the end. > - when old_len > len - 1, the new buffer is NUL terminated in an obfuscated > way (calloc() has filled it with NULs and the memcpy() doesn't overwrite > them all). Indeed, that is exactly the intent. -Dimitry --Apple-Mail=_5733E18B-193D-4A27-B386-DDD252477B54 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.2 iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCXKUMwwAKCRCwXqMKLiCW o5KgAJsHYRWGvsFCC9jmrS4ylTKqCR7Z8gCdGcjmXMW6sJIuQMwjUD0KPg0y9BY= =+1zd -----END PGP SIGNATURE----- --Apple-Mail=_5733E18B-193D-4A27-B386-DDD252477B54--