* A bug in Gnat, or in my code?
@ 2004-03-11 3:18 Björn Persson
2004-03-11 7:47 ` Preben Randhol
2004-03-12 2:59 ` Björn Persson
0 siblings, 2 replies; 17+ messages in thread
From: Björn Persson @ 2004-03-11 3:18 UTC (permalink / raw)
This program, when compiled with Gnat 3.3.2 and run on Fedora Core 1,
raises Storage_Error on line 7 (because of a segmentation fault):
procedure Error is -- 1
-- 2
procedure Proc (NullS : String) is -- 3
type SA is access String; -- 4
Point : SA := new String (1 .. 0); -- 5
begin -- 6
Point.all := NullS; -- 7
end Proc; -- 8
-- 9
S : String := "s"; -- 10
begin -- 11
Proc(S(3 .. 1)); -- 12
end Error; -- 13
If I change 3 to 2 on line 12 there is no error. As far as I can see,
(3..1) should be as legal as (2..1).
Am I right that this is a bug in Gnat?
--
Björn Persson
jor ers @sv ge.
b n_p son eri nu
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
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 14:29 ` Björn Persson
2004-03-12 2:59 ` Björn Persson
1 sibling, 2 replies; 17+ messages in thread
From: Preben Randhol @ 2004-03-11 7:47 UTC (permalink / raw)
To: comp.lang.ada
Bj�rn Persson <spam-away@nowhere.nil> wrote on 11/03/2004 (08:22) :
> This program, when compiled with Gnat 3.3.2 and run on Fedora Core 1,
> raises Storage_Error on line 7 (because of a segmentation fault):
>
> procedure Error is -- 1
> -- 2
> procedure Proc (NullS : String) is -- 3
> type SA is access String; -- 4
> Point : SA := new String (1 .. 0); -- 5
> begin -- 6
> Point.all := NullS; -- 7
> end Proc; -- 8
> -- 9
> S : String := "s"; -- 10
> begin -- 11
> Proc(S(3 .. 1)); -- 12
> end Error; -- 13
>
> If I change 3 to 2 on line 12 there is no error. As far as I can see,
> (3..1) should be as legal as (2..1).
>
> Am I right that this is a bug in Gnat?
I don't get this behaviour in gnat 3.15p so it is probably a gnat 3.3.2
bug. That said what are you trying to do with the code? It looks wierd
to me.
--
Preben Randhol -------------- http://www.pvv.org/~randhol/Ada95 --
�For me, Ada95 puts back the joy in programming.�
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 7:47 ` Preben Randhol
@ 2004-03-11 12:48 ` Georg Bauhaus
2004-03-11 13:59 ` Björn Persson
2004-03-11 14:29 ` Björn Persson
1 sibling, 1 reply; 17+ messages in thread
From: Georg Bauhaus @ 2004-03-11 12:48 UTC (permalink / raw)
Preben Randhol <randhol+abuse@pvv.org> wrote:
:
: I don't get this behaviour in gnat 3.15p so it is probably a gnat 3.3.2
: bug.
Fine with GCC 3.1 (1252) on Mac OS X too.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 12:48 ` Georg Bauhaus
@ 2004-03-11 13:59 ` Björn Persson
2004-03-12 16:21 ` Florian Villoing
0 siblings, 1 reply; 17+ messages in thread
From: Björn Persson @ 2004-03-11 13:59 UTC (permalink / raw)
Georg Bauhaus wrote:
> Preben Randhol <randhol+abuse@pvv.org> wrote:
> :
> : I don't get this behaviour in gnat 3.15p so it is probably a gnat 3.3.2
> : bug.
>
> Fine with GCC 3.1 (1252) on Mac OS X too.
Okay, seems like it might be a regression then.
I guess I should try a 3.4 snapshot before I file a bug report.
--
Björn Persson
jor ers @sv ge.
b n_p son eri nu
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 13:59 ` Björn Persson
@ 2004-03-12 16:21 ` Florian Villoing
2004-03-12 23:01 ` Björn Persson
0 siblings, 1 reply; 17+ messages in thread
From: Florian Villoing @ 2004-03-12 16:21 UTC (permalink / raw)
Bj�rn Persson <spam-away@nowhere.nil> wrote in message news:<3h_3c.85772$dP1.242518@newsc.telia.net>...
> Georg Bauhaus wrote:
>
> > Preben Randhol <randhol+abuse@pvv.org> wrote:
> > :
> > : I don't get this behaviour in gnat 3.15p so it is probably a gnat 3.3
> .2
> > : bug.
> >
> > Fine with GCC 3.1 (1252) on Mac OS X too.
>
> Okay, seems like it might be a regression then.
>
> I guess I should try a 3.4 snapshot before I file a bug report.
It seems to be OK on FreeBSD 5.2 with gcc-3.4 compiled from sources :
villoing:~/test$ gcc -v
Reading specs from /usr/home/villoing/install/gcc/bin/../lib/gcc/i386-unknown-freebsd5.2/3.4.0/specs
Configured with: ../gcc/configure --prefix=/home/villoing/install/gcc
--disable-shared --with-libiconv-prefix=/usr/local/lib
--disable-werror --enable-languages=c,ada
Thread model: posix
gcc version 3.4.0 20040305 (prerelease)
villoing:~/test$ gnatmake -f -gnatv error.adb
gcc -c -gnatv error.adb
GNAT 3.4.0 20040305 (prerelease) Copyright 1992-2004 Free Software
Foundation, Inc.
Compiling: error.adb (source file time stamp: 2004-03-12 16:11:18)
15 lines: No errors
gnatbind -x error.ali
gnatlink error.ali
villoing:~/test$ ./error
villoing:~/test
Florian
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 7:47 ` Preben Randhol
2004-03-11 12:48 ` Georg Bauhaus
@ 2004-03-11 14:29 ` Björn Persson
2004-03-11 14:59 ` Preben Randhol
2004-03-11 15:08 ` Preben Randhol
1 sibling, 2 replies; 17+ messages in thread
From: Björn Persson @ 2004-03-11 14:29 UTC (permalink / raw)
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.
--
Björn Persson
jor ers @sv ge.
b n_p son eri nu
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
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 15:08 ` Preben Randhol
1 sibling, 1 reply; 17+ messages in thread
From: Preben Randhol @ 2004-03-11 14:59 UTC (permalink / raw)
To: comp.lang.ada
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/
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 14:59 ` Preben Randhol
@ 2004-03-11 17:08 ` Björn Persson
2004-03-11 17:14 ` Preben Randhol
0 siblings, 1 reply; 17+ messages in thread
From: Björn Persson @ 2004-03-11 17:08 UTC (permalink / raw)
Preben Randhol wrote:
> I see. I think you have a bug in that you forgot to trim the text.
No, that's intentional. There might be cases where the value must be
used as it is, with possible spaces. In fact, I just removed the Trim on
the name. I improved another part of the program and then the trimming
became unnecessary.
> 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.
The Trim you inserted hides the bug, because Trim returns a more
conventional null string that doesn't cause problems in
To_Unbounded_String. After I removed it, your program crashes for me.
Did you try my test program on that version of Gnat?
--
Björn Persson
jor ers @sv ge.
b n_p son eri nu
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 17:08 ` Björn Persson
@ 2004-03-11 17:14 ` Preben Randhol
2004-03-11 18:15 ` Björn Persson
0 siblings, 1 reply; 17+ messages in thread
From: Preben Randhol @ 2004-03-11 17:14 UTC (permalink / raw)
On 2004-03-11, Bj�rn Persson <spam-away@nowhere.nil> wrote:
> Preben Randhol wrote:
>
>> I see. I think you have a bug in that you forgot to trim the text.
>
> No, that's intentional. There might be cases where the value must be
> used as it is, with possible spaces. In fact, I just removed the Trim on
> the name. I improved another part of the program and then the trimming
> became unnecessary.
>
>> 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.
>
> The Trim you inserted hides the bug, because Trim returns a more
> conventional null string that doesn't cause problems in
> To_Unbounded_String. After I removed it, your program crashes for me.
>
> Did you try my test program on that version of Gnat?
>
% apt-get install gnat-3.3
(I just love the package system in Debian. One command and it is
installed :-) )
Now to the case. I removed both trims and now I get:
% gnatmake -gnatv -f klyv_test
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 17:12:00)
45 lines: No errors
gnatbind -x klyv_test.ali
gnatlink klyv_test.ali
k-083152(randhol:~)% ./klyv_test
Ada 95 = morsomt => Ada 95 & morsomt
raised STORAGE_ERROR : stack overflow (or erroneous memory access)
Do you get a STORAGE_ERROR or do you get a segmentation fault?
--
Rox-Filer; *the* file manager => http://rox.sf.net/
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 17:14 ` Preben Randhol
@ 2004-03-11 18:15 ` Björn Persson
0 siblings, 0 replies; 17+ messages in thread
From: Björn Persson @ 2004-03-11 18:15 UTC (permalink / raw)
Preben Randhol wrote:
> % apt-get install gnat-3.3
>
> (I just love the package system in Debian. One command and it is
> installed :-) )
Yes, that's nice. Yum does the same in Fedora, (And there's a version of
Apt for Fedora too.)
> Now to the case. I removed both trims and now I get:
>
>
> % gnatmake -gnatv -f klyv_test
> 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 17:12:00)
> 45 lines: No errors
> gnatbind -x klyv_test.ali
> gnatlink klyv_test.ali
> k-083152(randhol:~)% ./klyv_test
> Ada 95 = morsomt => Ada 95 & morsomt
>
> raised STORAGE_ERROR : stack overflow (or erroneous memory access)
Okay, then I won't report it to Redhat.
> Do you get a STORAGE_ERROR or do you get a segmentation fault?
You could say I get both. :-) Running from a shell I get the same
message as you:
[bjorn@groucho Parafras]$ ./error
raised STORAGE_ERROR : stack overflow (or erroneous memory access)
[bjorn@groucho Parafras]$ ./klyv_test
Ada 95 = morsomt => Ada 95 & morsomt
raised STORAGE_ERROR : stack overflow (or erroneous memory access)
Running in GDB (inside GPS) I first get "Program received signal
SIGSEGV, Segmentation fault." If I try to continue from there,
Storage_Error is raised and the program terminates. So the SIGSEGV
signal is translated to a Storage_Error.
--
Björn Persson
jor ers @sv ge.
b n_p son eri nu
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-11 14:29 ` Björn Persson
2004-03-11 14:59 ` Preben Randhol
@ 2004-03-11 15:08 ` Preben Randhol
1 sibling, 0 replies; 17+ messages in thread
From: Preben Randhol @ 2004-03-11 15:08 UTC (permalink / raw)
To: comp.lang.ada
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.�
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
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-12 2:59 ` Björn Persson
2004-03-12 5:25 ` Per Sandberg
2004-03-12 11:11 ` Manuel Collado
1 sibling, 2 replies; 17+ messages in thread
From: Björn Persson @ 2004-03-12 2:59 UTC (permalink / raw)
There is now a bug report in the GCC Bugzilla, if anyone is interested:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14543
--
Björn Persson
jor ers @sv ge.
b n_p son eri nu
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
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
1 sibling, 1 reply; 17+ messages in thread
From: Per Sandberg @ 2004-03-12 5:25 UTC (permalink / raw)
To: Björn Persson, comp.lang.ada
It is fixed in the latest ACT version of GNAT
/Per
Bj�rn Persson wrote:
> There is now a bug report in the GCC Bugzilla, if anyone is interested:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14543
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: A bug in Gnat, or in my code?
2004-03-12 2:59 ` Björn Persson
2004-03-12 5:25 ` Per Sandberg
@ 2004-03-12 11:11 ` Manuel Collado
2004-03-12 23:01 ` Björn Persson
1 sibling, 1 reply; 17+ messages in thread
From: Manuel Collado @ 2004-03-12 11:11 UTC (permalink / raw)
Bj�rn Persson wrote:
> There is now a bug report in the GCC Bugzilla, if anyone is interested:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14543
I've reproduced the bug with the DJGPP port of gcc 3.3.3
F:\PRUEBAS\ADA>gcc --version
gcc.exe (GCC) 3.3.3
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
F:\PRUEBAS\ADA>gnatmake null_slice_error
gcc -c null_slice_error.adb
null_slice_error.adb:1:11: warning: file name does not match unit name,
should be "nuslierr.adb"
gnatbind -x null_slice_error.ali
gnatlink null_slice_error.ali
F:\PRUEBAS\ADA>F:\PRUEBAS\ADA\null_slice_error.exe
Exiting due to signal SIGSEGV
General Protection Fault at eip=000018fa
...
--
To reply by e-mail, please remove the extra dot
in the given address: m.collado -> mcollado
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2004-03-12 23:01 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox