public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Robert Dewar <dewar@adacore.com>
To: Samuel Tardieu <sam@rfc1149.net>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] ada/30827: Zero-terminate Ada-generated version string
Date: Mon, 18 Aug 2008 01:10:00 -0000	[thread overview]
Message-ID: <48A89F65.3000209@adacore.com> (raw)
In-Reply-To: <20080817141739.AAEA28047@dawn.rfc1149.net>

Sam, here is my slightly modified version of your
patch, certainly fine to install:

> --- bindgen.adb (revision 134502)
> +++ bindgen.adb (working copy)
> @@ -2299,17 +2299,19 @@
>                 WBI ("   gnat_exit_status : Integer;");
>                 WBI ("   pragma Import (C, gnat_exit_status);");
>              end if;
> -
> -            --  Generate the GNAT_Version and Ada_Main_Program_Name info only
> -            --  for the main program. Otherwise, it can lead under some
> -            --  circumstances to a symbol duplication during the link (for
> -            --  instance when a C program uses 2 Ada libraries)
>           end if;
> 
> +         --  Generate the GNAT_Version and Ada_Main_Program_Name info only for
> +         --  the main program. Otherwise, it can lead under some circumstances
> +         --  to a symbol duplication during the link (for instance when a C
> +         --  program uses two Ada libraries). Also zero terminate the string
> +         --  so that its end can be found reliably at run time.
> +
>           WBI ("");
>           WBI ("   GNAT_Version : constant String :=");
>           WBI ("                    ""GNAT Version: " &
> -                                Gnat_Version_String & """;");
> +                                   Gnat_Version_String &
> +                                   """ & ASCII.NUL;");
>           WBI ("   pragma Export (C, GNAT_Version, ""__gnat_version"");");
> 
>           WBI ("");

> --- g-comver.adb        (revision 134444)
> +++ g-comver.adb        (working copy)
> @@ -53,15 +53,19 @@
> 
>     function Version return String is
>     begin
> -      --  Search for terminating right paren
> +      --  Search for terminating right paren or NUL ending the string
> 
>        for J in Ver_Prefix'Length + 1 .. GNAT_Version'Last loop
>           if GNAT_Version (J) = ')' then
>              return GNAT_Version (Ver_Prefix'Length + 1 .. J);
>           end if;
> +
> +         if GNAT_Version (J) = Character'Val (0) then
> +            return GNAT_Version (Ver_Prefix'Length + 1 .. J - 1);
> +         end if;
>        end loop;
> 
> -      --  This should not happen (no right paren found)
> +      --  This should not happen (no right paren or NUL found)
> 
>        return GNAT_Version;
>     end Version;

And here is the best I can come up with for a test program:

> with GNAT.Compiler_Version;
> procedure TestVer is
>    package Vsn is new GNAT.Compiler_Version;
>    use Vsn;
>    X : String := Version;
> begin
>    if X'Length = 46 then
>       -- 46 = Ver_Len_Max + Ver_Prefix
>       -- actual version should be shorter than this
>       raise Program_Error;
>    end if;
> end;


      reply	other threads:[~2008-08-17 22:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-17 16:37 Samuel Tardieu
2008-08-18  1:10 ` Robert Dewar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48A89F65.3000209@adacore.com \
    --to=dewar@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=sam@rfc1149.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).