From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4788 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 16:22:46 -0400 Message-ID: References: <20140404141515.GD3034@port70.net> <20140404150705.GN26358@brightrain.aerifal.cx> <20140404185413.GH3034@port70.net> 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 1396642984 21233 80.91.229.3 (4 Apr 2014 20:23:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Apr 2014 20:23:04 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4792-gllmg-musl=m.gmane.org@lists.openwall.com Fri Apr 04 22:22:59 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 1WWAde-00041J-UJ for gllmg-musl@plane.gmane.org; Fri, 04 Apr 2014 22:22:59 +0200 Original-Received: (qmail 1962 invoked by uid 550); 4 Apr 2014 20:22:58 -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 1954 invoked from network); 4 Apr 2014 20:22:58 -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=b6BTsWIz8R3dm+jiqi+ctzoedDVHfMtD6CfdYM+HBG4=; b=z1lTvknBP21kWJoLjPmzblelrUFyUUtTaMO4XliHbcgHf3Qf2xqqSZbLJST7diXZOs 4r2TM+8pTzqZl8DbUg+OnOEa8tO6NSepuDdPcxYNadQa516PAg2JSZq5M0peABZgcQU+ /LUT2Nyv69ltcflO7y5VtvWKj+Jn3VBSzT4PT9/1uEDbauSIh+inmTwYV1E5gXWAfuWk riUzH7oP+q5GlBO1c7iv/RjfABaPiohJAEAjD/2IMc7SVCslptjXc9O5zwzVTGKpDnIw 3ATpA5cAyItb0mHe3cuQPNUqPKIqDFk541VqQcvj02TZDTT/ndWJxtxAHmOIDrQL9HIG xn8g== X-Received: by 10.180.210.171 with SMTP id mv11mr7234915wic.44.1396642966371; Fri, 04 Apr 2014 13:22:46 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:4788 Archived-At: 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. Morten On Fri, Apr 4, 2014 at 4:01 PM, Morten Welinder wrote: > In fmt_fmt, the rounding decision is done using this test: > > /* Decide whether to round by probing round+small */ > if (round+small != round) { ... > > Why is this done with long double? > > The reason I ask is that the Valgrind situation improves a lot if > this is done with doubles. > > (Valgrind situation: Valgrind emulates long doubles, poorly, by using > simple doubles. See, for example, https://bugs.kde.org/show_bug.cgi?id=164298) > > Morten > > > > > On Fri, Apr 4, 2014 at 2:54 PM, Szabolcs Nagy wrote: >> * Morten Welinder [2014-04-04 13:42:30 -0400]: >>> It looks like the LDBL_EPSILON version could be used in >>> >>> roundl.c >>> modfl.c >>> ceill.c >>> floorl.c >>> >>> in the definition of TOINT instead of enumerating choices for >>> LDBL_MANT_DIG. It's basically the same thing going on >> >> yes, that would be a bit nicer >> (although other long double formats won't be supported anytime soon) >> >> (note that in the future these implementations may need to change >> the current versions raise inexact flag if result!=input, but the >> next version of the floating-point extension standard for c >> will require suppressing inexact, which i dont know how to do >> with simple arithmetics efficiently without accessing the fenv..) >> >>> While I was looking for that, I noticed that this modfl fallback looks >>> problematic. Even if long double and double are the same thing >>> under the hood, I don't think you can cast pointers like that and >>> assume it works. It needs a temporary. >>> >>> #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 >>> long double modfl(long double x, long double *iptr) >>> { >>> return modf(x, (double *)iptr); >>> } >> >> yes, this is an aliasing violation, nice catch >> >> the original idea was to allow tail call opt for these wrappers, >> so they are a single branch instruction, we should fix it but >> i think we can rely on that the ptr representations are the same: >> >> long double modfl(long double x, long double *iptr) >> { >> union {long double *ld; double *d;} u = {iptr}; >> return modf(x, u.d); >> }