From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4799 Path: news.gmane.org!not-for-mail From: Morten Welinder Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf issues Date: Fri, 4 Apr 2014 20:01:00 -0400 Message-ID: References: <20140404141515.GD3034@port70.net> <20140404150705.GN26358@brightrain.aerifal.cx> <20140404185413.GH3034@port70.net> <20140404210837.GS26358@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1396656079 32363 80.91.229.3 (5 Apr 2014 00:01:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 5 Apr 2014 00:01:19 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4803-gllmg-musl=m.gmane.org@lists.openwall.com Sat Apr 05 02:01:13 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WWE2r-0005EB-7Y for gllmg-musl@plane.gmane.org; Sat, 05 Apr 2014 02:01:13 +0200 Original-Received: (qmail 1545 invoked by uid 550); 5 Apr 2014 00:01:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 1534 invoked from network); 5 Apr 2014 00:01:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Z69ZqtGoCHzvugR5BJBKnwYTxxpJVCxZkB0M8484q0c=; b=ifcYmlrWCrA9gumDyXfXcz8n1eSL+DvIY6vNuQnn4BEu7v7D7CY5fMuIulFqMFl38H Q+lb5GnWQVCrL/bqTbC7S+YJ17w3JrGDlC8AoNbfWrC8Sd0RpIAyoo0skh8mxkZ+N9sw B+ieFF+wFjshfu3q9gQtp00DJx5go7cwdlDSjugLbXF2okwNQNWMybXYyTNJuUEBJ9Dd +E7XODBAGsbnKqyF1uca4n0RgTxeUigl4JOo0LHgFExb8aVE+oLDhvFOJkj32KjI3GeN kEaQU3rCsTMazYcKSHbvvX9acMHJdcisK+b+gq2bhmTE57uoiDXz/LwzCjO1DcSqN+Hb FRtg== X-Received: by 10.180.98.71 with SMTP id eg7mr8021838wib.31.1396656060870; Fri, 04 Apr 2014 17:01:00 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:4799 Archived-At: I *think* the right fix is to add the following "if' statement into the rounding loop: while (*d > 999999999) { *d--=0; if (d < a) *--a = 0; (*d)++; } This also ought to make the d wrote: >> Were you able to determine what data it clobbers (in practice; >> obviously this is compiler-specific) and whether the clobber >> has any observable effects? > > It clobbers uninitialized parts of "big". If you add > > for (i = 0; i < sizeof(big)/sizeof(big[0]); i++) big[i] = 12345678; > > then it will consistently print "1.23E+16" which is a bit off, :-) If > you instead > initialize like this: > > for (i = 0; i < sizeof(big)/sizeof(big[0]); i++) big[i] = 999999999; > > then I get "1E+15939" which is fairly impressive. Also, in this case it will > clobber whatever happened to come before "big". > > Morten > > > > On Fri, Apr 4, 2014 at 5:08 PM, Rich Felker wrote: >> On Fri, Apr 04, 2014 at 04:22:46PM -0400, Morten Welinder wrote: >>> Another printf issue has shown up, this time with memory corruption. >>> >>> printf ("%.3E\n", 999999999.0); >>> >>> The rounding test correctly decides that it needs to round this value >>> up to 1E+09. It is, however, utterly unprepared for having nowhere to >>> put the carry. It happily accesses and changes one or more elements >>> before the one that held 999999999. >> >> I suspect this may be true; if so, it's a very nice catch. Were you >> able to determine what data it clobbers (in practice; obviously this >> is compiler-specific) and whether the clobber has any observable >> effects? >> >> Rich