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 #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-02-07 17:43:25 UTC ---
On Mon, Feb 07, 2011 at 04:12:00PM +0000, jakub at gcc dot gnu.org wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47633
> 
> Jakub Jelinek <jakub at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |jakub at gcc dot gnu.org
> 
> --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-02-07 16:11:58 UTC ---
> Why should there be the extra space at the end?  Doesn't make sense.
> IMHO either pass len - 1 to gfc_get_character_expr or don't count '\0' in len
> (i.e. remove the + 1) and use len + 1 in alloca.  You shouldn't use alloca btw,
> but XALLOCAVEC (char, len).
> 

You're right. I could do the len - 1, but when I tried that
I misinterpreted the results of the test program.  Here's an
update diff and testcase.  I'll start a regression test shortly,
and submit a patch for approval.

troutmask:sgk[218] svn diff simplify.c
Index: simplify.c
===================================================================
--- simplify.c  (revision 169830)
+++ simplify.c  (working copy)
@@ -6845,8 +6845,8 @@ gfc_simplify_compiler_version (void)
   size_t len;

   len = strlen ("GCC version ") + strlen (version_string) + 1;
-  buffer = (char*) alloca (len);
+  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);
+                                &gfc_current_locus, buffer, len - 1);
 }

troutmask:sgk[407] cat h.f90
! { dg-do run }
! PR fortran/47633
program testenv
    use iso_fortran_env
    character(len=60) v
    integer n
    v = compiler_version()
    n = len(compiler_version())
    if (ichar(v(n:n)) /= 41 .or. ichar(v(n+1:n+1)) /= 32) call abort()
end program testenv


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