From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25511 invoked by alias); 7 Feb 2011 19:19:59 -0000 Received: (qmail 25501 invoked by uid 22791); 7 Feb 2011 19:19:58 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_SG X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Feb 2011 19:19:54 +0000 From: "sgk at troutmask dot apl.washington.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/47633] Result of COMPILER_VERSION() has NULL byte appended X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sgk at troutmask dot apl.washington.edu X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Mon, 07 Feb 2011 19:37:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00897.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47633 --- Comment #6 from Steve Kargl 2011-02-07 19:19:37 UTC --- On Mon, Feb 07, 2011 at 06:58:39PM +0000, burnus at gcc dot gnu.org wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47633 > > > if (ichar(v(n:n)) /= 41 .or. ichar(v(n+1:n+1)) /= 32) call abort() > > (In reply to comment #4) > > The testcase is bad, because for vanilla gcc releases there is no (prerelease) > > etc. string at all (DEV-PHASE is empty), and because it hardcodes ASCII values, > > so I'm afraid it could fail on EBCDIC or other targets. > > Regarding the char: using "iachar" instead of "ichar" should work. That still doesn't help. The testcase is looking for the last valid character in the string and a following space. Jakub's point is that '(experimental)' in the string 'GCC version 4.6.0 20110204 (experimental)' is sometimes not present, so checking for ')' won't work in all situations. I'll suggest that we simply omit a testcase for this PR. > len = strlen ("GCC version ") + strlen (version_string) + 1; > + buffer = XALLOCAVEC (char, len); > snprintf (buffer, len, "GCC version %s", version_string); > return gfc_get_character_expr (gfc_default_character_kind, > + &gfc_current_locus, buffer, len - 1); > > I wonder whether one should strip the "+1" in the first line and use "len+1" > for alloca/snprintf; it seems to be easier to follow than the "len - 1" in the > last line. Sure, no problem. Here's a tested patch. Index: simplify.c =================================================================== --- simplify.c (revision 169830) +++ simplify.c (working copy) @@ -6844,9 +6844,9 @@ gfc_simplify_compiler_version (void) char *buffer; size_t len; - len = strlen ("GCC version ") + strlen (version_string) + 1; - buffer = (char*) alloca (len); - snprintf (buffer, len, "GCC version %s", version_string); + len = strlen ("GCC version ") + strlen (version_string); + buffer = XALLOCAVEC (char, len + 1); + snprintf (buffer, len + 1, "GCC version %s", version_string); return gfc_get_character_expr (gfc_default_character_kind, &gfc_current_locus, buffer, len); }