This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/47633] Result of COMPILER_VERSION() has NULL byte appended


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47633

--- Comment #6 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 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);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]