From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11615 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: calloc question about clearing allocated memory Date: Tue, 27 Jun 2017 15:13:27 +0200 Message-ID: <20170627131327.GD2032@port70.net> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1498569229 23546 195.159.176.226 (27 Jun 2017 13:13:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 27 Jun 2017 13:13:49 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) Cc: musl@lists.openwall.com To: Vicente Bergas Original-X-From: musl-return-11628-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 27 15:13:44 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dPqJH-0005g6-Sn for gllmg-musl@m.gmane.org; Tue, 27 Jun 2017 15:13:39 +0200 Original-Received: (qmail 25909 invoked by uid 550); 27 Jun 2017 13:13:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 25888 invoked from network); 27 Jun 2017 13:13:39 -0000 Mail-Followup-To: Vicente Bergas , musl@lists.openwall.com Content-Disposition: inline In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:11615 Archived-At: * Vicente Bergas [2017-06-26 23:30:53 +0200]: > Hello, > when compiling a program against the musl libc and running it under > valgrind, then it reports lots of uninitialized value errors. > I have tracked them down to only two sources: > http://git.musl-libc.org/cgit/musl/tree/src/string/strlen.c?id=3De6def544= #n15 > http://git.musl-libc.org/cgit/musl/tree/src/malloc/malloc.c?id=3De6def544= #n375 >=20 > The first one about strlen is clearly an optimization everybody would > like to have, but the second one in __malloc0 is not that obvious. > Please, could that be explained: why is *z read just before being > cleared? > In fact it is counter-intuitive and looks like an overhead. > In case there is a reason for it, it would be nice to put an > explanatory comment there. Otherwise, that extra read could be > removed to make valgrind happy. this should be the faq of the month.. a zero page does not take up resources, however when it is written (even if that's just 0) the page gets dirty and it does take up resources (and the write operation would cause a page fault introducing significant delays) so if(*z) *z=3D0; should be an obvious optimization. that said the current code is not optimal and an improvement was just posted: http://www.openwall.com/lists/musl/2017/06/26/1 but that won't fix the valgrind issue: to fix that valgrind just needs to be taught not to report uninitialized error for calloced memory. >=20 > Regards, > Vicen=E7. >=20 > P.S.: Please, CC me as I am not subscribed to the list.