From: Preben Randhol <randhol+abuse@pvv.org>
To: comp.lang.ada@ada-france.org
Subject: Re: A bug in Gnat, or in my code?
Date: Thu, 11 Mar 2004 16:08:39 +0100
Date: 2004-03-11T16:08:39+01:00 [thread overview]
Message-ID: <mailman.92.1079017740.327.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <lJ_3c.85773$dP1.242524@newsc.telia.net>
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;
-------------------------------------
Preben
--
Preben Randhol -------------- http://www.pvv.org/~randhol/Ada95 --
�For me, Ada95 puts back the joy in programming.�
next prev parent reply other threads:[~2004-03-11 15:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-11 3:18 A bug in Gnat, or in my code? Björn Persson
2004-03-11 7:47 ` Preben Randhol
2004-03-11 12:48 ` Georg Bauhaus
2004-03-11 13:59 ` Björn Persson
2004-03-12 16:21 ` Florian Villoing
2004-03-12 23:01 ` Björn Persson
2004-03-11 14:29 ` Björn Persson
2004-03-11 14:59 ` Preben Randhol
2004-03-11 17:08 ` Björn Persson
2004-03-11 17:14 ` Preben Randhol
2004-03-11 18:15 ` Björn Persson
2004-03-11 15:08 ` Preben Randhol [this message]
2004-03-12 2:59 ` Björn Persson
2004-03-12 5:25 ` Per Sandberg
2004-03-12 23:01 ` Björn Persson
2004-03-12 11:11 ` Manuel Collado
2004-03-12 23:01 ` Björn Persson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox