From patchwork Mon Feb 28 20:34:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 84865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 69D04B711D for ; Tue, 1 Mar 2011 07:34:21 +1100 (EST) Received: (qmail 1306 invoked by alias); 28 Feb 2011 20:34:20 -0000 Received: (qmail 1168 invoked by uid 22791); 28 Feb 2011 20:34:19 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Feb 2011 20:34:15 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1SKYEQX029687 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 28 Feb 2011 15:34:14 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1SKYDVt032330 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 28 Feb 2011 15:34:14 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p1SKYDbr025558 for ; Mon, 28 Feb 2011 21:34:13 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p1SKYDcP025556 for gcc-patches@gcc.gnu.org; Mon, 28 Feb 2011 21:34:13 +0100 Date: Mon, 28 Feb 2011 21:34:13 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix quadmath_snprintf behavior on string truncation Message-ID: <20110228203412.GM30899@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi! snprintf of course needs to zero terminate the provided string always unless size is 0, but quadmath_snprintf was errorneously not terminating it if we hit the user supplied size. Fixed thusly, committed to trunk after bootstrap/regtest on x86_64-linux and i686-linux. 2011-02-28 Jakub Jelinek * printf/quadmath-printf.c (quadmath_snprintf): Make sure that for size > 0 str is always zero terminated. Jakub --- libquadmath/printf/quadmath-printf.c.jj 2011-02-16 11:13:15.000000000 +0100 +++ libquadmath/printf/quadmath-printf.c 2011-02-28 18:30:07.590808338 +0100 @@ -256,7 +256,7 @@ quadmath_snprintf (char *str, size_t siz qfp.fp = NULL; qfp.str = str; - qfp.size = size; + qfp.size = size ? size - 1 : 0; qfp.len = 0; qfp.file_p = 0; @@ -265,7 +265,7 @@ quadmath_snprintf (char *str, size_t siz else __quadmath_printf_fp (&qfp, &info, (const void *const *)&fpnum_addr2); - if (qfp.size) + if (size) *qfp.str = '\0'; return qfp.len;