From patchwork Tue May 20 13:40:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 1026 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id DECDF360076 for ; Tue, 20 May 2014 06:40:58 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14307373) id 93E5641CBD819; Tue, 20 May 2014 06:40:58 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx20.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id 58B6B41CBD819 for ; Tue, 20 May 2014 06:40:58 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; q=dns; s= default; b=yvANhKBTjGFDXGpMuxnf+LCsieOUHxoPT19IAwKtuF94VOu6zCfoe Uw3jsDA5OUbYkK3pBim55Awm6MfNjU1i/OvR/oaCbj/xDJpU7J+JY0kqrH/65ciJ gezGM8A62fpsEGCff+1ez5VcsLZ7xrDMn0vqVqHXXlPkvwPgqSho4E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; s=default; bh=oiymK3q6svbiNbUMp2ovhUlo8IQ=; b=O2iyVBkXaKHflQXpQN/zopSsXS43 DGqe+AufnogGJpyGAQTGoBjsihUqqt/XVPS4QDwpBMHa9QW/J+2LPDsx+3TBE+rI Tkvz9gyX2Y80XJ0s8UJ+1TgF9T/hrs8OtK204dbekXpPm1wPS7OP0y4BDMgk8cUe Z+0q/FkM8ajgX64= Received: (qmail 22670 invoked by alias); 20 May 2014 13:40:56 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 22657 invoked by uid 89); 20 May 2014 13:40:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: "Joseph S. Myers" , David Miller , Aurelien Jarno Subject: [PATCH] Fix strtold on 32-bit sparc (and probably others) (BZ #16965) Date: Tue, 20 May 2014 15:40:38 +0200 Message-Id: <1400593238-10317-1-git-send-email-aurelien@aurel32.net> X-DH-Original-To: glibc@patchwork.siddhesh.in This patch fixes an issue observed running the tst-strtod-round test on 32 bit sparc. In some conditions, strtold calls round_and_return, which in turn calls __mpn_rshift with cnt = 0, while stdlib/rshift.c explicitly says that cnts should satisfy 0 < CNT < BITS_PER_MP_LIMB. In this case, the code end up doing a logical shift right of the same amount than the register, which is undefined in the C standard. Due to this bug, 32-bit sparc does not correctly convert the value "0x1p-16446", but it is likely that other architectures are also affected for other input values. --- ChangeLog | 6 ++++++ stdlib/strtod_l.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc75ff2..5755561 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-05-20 Aurelien Jarno + + [BZ #16965] + * stdlib/strtod_l.c (round_and_return): Add code to shift limbs + when the shift amount is modulo the limb size. + 2014-05-20 Will Newton * sysdeps/unix/sysv/linux/aarch64/nptl/sysdep-cancel.h (PSEUDO): diff --git a/stdlib/strtod_l.c b/stdlib/strtod_l.c index 6707e48..3c449c7 100644 --- a/stdlib/strtod_l.c +++ b/stdlib/strtod_l.c @@ -243,9 +243,14 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative, more_bits |= ((round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0); - (void) __mpn_rshift (retval, &retval[shift / BITS_PER_MP_LIMB], - RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB), - shift % BITS_PER_MP_LIMB); + /* __mpn_rshift requires 0 < shift < BITS_PER_MP_LIMB. */ + if ((shift % BITS_PER_MP_LIMB) != 0) + (void) __mpn_rshift (retval, &retval[shift / BITS_PER_MP_LIMB], + RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB), + shift % BITS_PER_MP_LIMB); + else + for (i = 0; i < RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB); i++) + retval[i] = retval[i + (shift / BITS_PER_MP_LIMB)]; MPN_ZERO (&retval[RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB)], shift / BITS_PER_MP_LIMB); }