From patchwork Thu Apr 19 20:35:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Meyering X-Patchwork-Id: 153868 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 0B2D7B702A for ; Fri, 20 Apr 2012 06:36:01 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1335472564; h=Comment: DomainKey-Signature:Received:Received:Received:Received:From:To: Cc:Subject:References:Date:Message-ID:Lines:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=iv8MSUX /1/ZWLTV8fEB93Ol0ka0=; b=SORDqTnsqo6UO2IJjJc0o0X2oxVWVob4O9VeuPU MIOdxlyuWENGzxUtCcr9oky6XKBepHp/tNbDptayJLiIcFQQS3TwVes7isUUF2Hs 3snElNnoVQuoHCTZtQXXN3B4sp7Om/8Hk2ZkCEDBb6cFgndr1SSs28mEi3uUp2Gw guh4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:From:To:Cc:Subject:References:Date:Message-ID:Lines:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Rpfl/hy3jXErw8BX/NDm2GkLimIq1OhLKz852aI3wbUx14fuFt8B4fTVHveu+1 BQ+4hgCR0DKYs/EnPWZGd4arWYvg9az1AKSMi3hHnV0wtf5TLAeUdXmcg0hBQoro kUJBEyUyIJz5PQdMjDS/7ln6cyPAjSCmE7aG7dcaUvZ40=; Received: (qmail 2980 invoked by alias); 19 Apr 2012 20:35:55 -0000 Received: (qmail 2904 invoked by uid 22791); 19 Apr 2012 20:35:54 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, TW_CP, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx.meyering.net (HELO mx.meyering.net) (88.168.87.75) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Apr 2012 20:35:41 +0000 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 266B560244; Thu, 19 Apr 2012 22:35:39 +0200 (CEST) From: Jim Meyering To: Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] genmodes: don't truncate a mode name of length >= 7 References: <87hawgq9yg.fsf@rho.meyering.net> <87fwbzq5qr.fsf@rho.meyering.net> Date: Thu, 19 Apr 2012 22:35:39 +0200 Message-ID: <8762cvmpd0.fsf_-_@rho.meyering.net> Lines: 105 MIME-Version: 1.0 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 Richard Guenther wrote: > Sure, my point was that the > > if (strlen (m->name) >= sizeof buf) > { > error ("%s:%d:mode name \"%s\" is too long", > m->file, m->line, m->name); > continue; > } > > check does not account for the (conditional) prepending of 'C' and the > snprintf would silently discard the last character of the name. Here's a patch for that. (passes make bootstrap) Incidentally it removes the name-length limitation of 7 and it hoists the xmalloc, which induces the single added free-before-continue. There was some clean-up along the way: "q" was easy to eliminate, and I pulled the two identical snprintf calls out of the "if" block and replaced them with the buf[0] assignment and memcpy. 2012-04-19 Jim Meyering * genmodes.c (make_complex_modes): Don't truncate a mode name of length 7 or more when prepending a "C". Suggested by Richard Guenther. gcc/genmodes.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) --- 1.7.10.208.gb4267 diff --git a/gcc/genmodes.c b/gcc/genmodes.c index 6bbeb6f..84517b9 100644 --- a/gcc/genmodes.c +++ b/gcc/genmodes.c @@ -427,7 +427,6 @@ make_complex_modes (enum mode_class cl, { struct mode_data *m; struct mode_data *c; - char buf[8]; enum mode_class cclass = complex_class (cl); if (cclass == MODE_RANDOM) @@ -435,6 +434,7 @@ make_complex_modes (enum mode_class cl, for (m = modes[cl]; m; m = m->next) { + char *p, *buf; size_t m_len; /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */ @@ -442,40 +442,34 @@ make_complex_modes (enum mode_class cl, continue; m_len = strlen (m->name); - if (m_len >= sizeof buf) - { - error ("%s:%d:mode name \"%s\" is too long", - m->file, m->line, m->name); - continue; - } + /* The leading "1 +" is in case we prepend a "C" below. */ + buf = (char *) xmalloc (1 + m_len + 1); /* Float complex modes are named SCmode, etc. Int complex modes are named CSImode, etc. This inconsistency should be eliminated. */ + p = 0; if (cl == MODE_FLOAT) { - char *p, *q = 0; - /* We verified above that m->name+NUL fits in buf. */ memcpy (buf, m->name, m_len + 1); p = strchr (buf, 'F'); - if (p == 0) - q = strchr (buf, 'D'); - if (p == 0 && q == 0) + if (p == 0 && strchr (buf, 'D') == 0) { error ("%s:%d: float mode \"%s\" has no 'F' or 'D'", m->file, m->line, m->name); + free (buf); continue; } - - if (p != 0) - *p = 'C'; - else - snprintf (buf, sizeof buf, "C%s", m->name); } + if (p != 0) + *p = 'C'; else - snprintf (buf, sizeof buf, "C%s", m->name); + { + buf[0] = 'C'; + memcpy (buf + 1, m->name, m_len + 1); + } - c = new_mode (cclass, xstrdup (buf), file, line); + c = new_mode (cclass, buf, file, line); c->component = m; } }