From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,23d2475711dc99b8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-11 07:15:14 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!peernews-us.colt.net!colt.net!easynet-quince!easynet.net!nnx.oleane.net!oleane!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Preben Randhol Newsgroups: comp.lang.ada Subject: Re: A bug in Gnat, or in my code? Date: Thu, 11 Mar 2004 15:59:44 +0100 Organization: Cuivre, Argent, Or Sender: Preben Randhol Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1079017222 62592 212.85.156.195 (11 Mar 2004 15:00:22 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Thu, 11 Mar 2004 15:00:22 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.5.1+cvs20040105i X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:6240 Date: 2004-03-11T15:59:44+01:00 In comp.lang.ada, you wrote: > Preben Randhol wrote: > >> That said what are you trying to do with the code? It looks wierd >> to me. > > Of course that code is useless. That's just a stripped test case. The > bug occurs in To_Unbounded_String, called from this procedure: > > procedure klyv(argument : in string; > namn : out unbounded_string; > text : out unbounded_string) is > use Ada.Strings; > use ada.strings.fixed; > pos : natural; > begin > pos := index(argument, "="); > if pos = 0 then > pos := argument'last + 1; > end if; > namn := to_unbounded_string( > trim(argument(argument'first .. pos - 1), both)); > text := to_unbounded_string( > argument(pos + 1 .. argument'last)); > end klyv; > > It splits a string of the format "name=value" into two. If there is no > equal sign, the whole string goes into Namn, and Text should become an > empty string. In that case To_Unbounded_String is called with > Argument(Argument'Last+2..Argument'Last), which triggers the bug. I see. I think you have a bug in that you forgot to trim the text. Anyhow I made a test of your program and ran it on gnat 3.3.3 from Debian and it works there. No crash. So maybe it is only the packaging of RedHat? A program shouldn't segmentation fault and this is typically an indication of a packaging/installation error. % gnatmake -f -gnatv klyv_test.adb gcc-3.3 -c -gnatv klyv_test.adb GNAT 3.3.3 (Debian) Copyright 1992-2002 Free Software Foundation, Inc. Compiling: klyv_test.adb (source file time stamp: 2004-03-11 14:46:48) 46 lines: No errors gnatbind -x klyv_test.ali gnatlink klyv_test.ali % ./klyv_test Ada 95 = morsomt => Ada 95&morsomt Ada 95 morsomt => Ada 95 morsomt& Here is my program: klyv_test.adb ------------------------------------- with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings; with Ada.Strings.Fixed; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure klyv_test is procedure klyv(argument : in string; namn : out unbounded_string; text : out unbounded_string) is use Ada.Strings; use ada.strings.fixed; pos : natural; begin pos := index(argument, "="); if pos = 0 then pos := argument'last + 1; end if; namn := to_unbounded_string( trim(argument(argument'first .. pos - 1), both)); text := to_unbounded_string( trim(argument(pos + 1 .. argument'last), both)); end klyv; Hoggestabbe1 : constant String := "Ada 95 = morsomt"; Hoggestabbe2 : constant String := "Ada 95 morsomt"; Tekst_foer : Unbounded_String; Tekst_etter : Unbounded_String; begin klyv (Hoggestabbe1, Tekst_foer, Tekst_etter); Put_Line (Hoggestabbe1 & " => " & To_String (Tekst_foer) & "&" & To_String (Tekst_etter)); klyv (Hoggestabbe2, Tekst_foer, Tekst_etter); Put_Line (Hoggestabbe2 & " => " & To_String (Tekst_foer) & "&" & To_String (Tekst_etter)); end klyv_test; ------------------------------------- -- Rox-Filer; *the* file manager => http://rox.sf.net/