* Assigning to dereferenced null access variable
@ 2000-11-05 0:00 Vincent Marciante
2000-11-07 0:00 ` Simpler Question (was Assigning to dereferenced null access variable) Vincent Marciante
0 siblings, 1 reply; 9+ messages in thread
From: Vincent Marciante @ 2000-11-05 0:00 UTC (permalink / raw)
In the following code, I expected a constraint_error to occur
after the line containing "???" but it did not occur. Is that
correct behavior?
Also, after that line, I expected the code in the two blocks
to behave the same but that was not the case. The following is the output that I get from OS/2 GNAT 3.12
abcd_Sequence.The_Characters.all = "abcd"
Null_Characters(1..0) = Null_Characters
Null_Sequence.The_Characters = null.
Null_Sequence.The_Characters(1..0) = Null_Characters
Null_Sequence.The_Characters(1..0) := Null_Characters(1..0) succeeded ?
Null_Sequence.The_Characters(1..0) := Null_Characters caused Constraint_Error ?
with Ada.Text_IO; Use Ada.Text_IO;
procedure Null_Sequence_Assignment is
type Characters is array (Positive range <>) of Character;
type Reference is access Characters;
type Character_Sequence is
record
The_Length : Natural := 0;
The_Characters : Reference;
end record;
Null_Characters : Characters(1..0);
abcd_Characters : Characters := "abcd";
Null_Sequence : Character_Sequence;
abcd_Sequence : Character_Sequence := (4, new Characters'(1=>'a',2=>'b',3=>'c',4=>'d'));
begin
abcd_Characters(1..0) := Null_Characters(1..0);
abcd_Characters(1..0) := Null_Characters;
Null_Characters := abcd_Characters(1..0);
abcd_Sequence.The_Characters(1..0) :=
Null_Characters;
abcd_Sequence.The_Characters(1..Null_Sequence.The_Length) :=
Null_Sequence.The_Characters(1..Null_Sequence.The_Length);
abcd_Sequence.The_Characters(1..0) :=
Null_Sequence.The_Characters(1..0);
abcd_Sequence.The_Characters(1..0) :=
Null_Characters;
put_line("abcd_Sequence.The_Characters.all = """
& String(abcd_Sequence.The_Characters.all) & '"');
--- ???
Null_Sequence.The_Characters(1..0) :=
-- Why no Constraint_Error here do to
-- dereferencing of null access value?
-- Is it due to allowed optimization?
abcd_Sequence.The_Characters(1..0);
if Null_Characters(1..0) = Null_Characters then
Put_Line("Null_Characters(1..0) = Null_Characters");
else
Put_Line("Null_Characters(1..0) /= Null_Characters");
end if;
if Null_Sequence.The_Characters = null then
Put_Line("Null_Sequence.The_Characters = null.");
else
Put_Line("Null_Sequence.The_Characters /= null.");
end if;
if Null_Sequence.The_Characters(1..0) = Null_Characters then
Put_Line("Null_Sequence.The_Characters(1..0) = Null_Characters");
else
Put_Line("Null_Sequence.The_Characters(1..0) /= Null_Characters");
end if;
begin
Null_Sequence.The_Characters(1..0) :=
Null_Characters(1..0);
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters(1..0) succeeded ?");
-- I thought that dereferencing The_Characters
-- would have caused Constraint_Error to occur.
exception
when Constraint_error =>
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters(1..0) caused Constraint_Error");
end;
begin
Null_Sequence.The_Characters(1..0) :=
Null_Characters;
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters succeeded");
exception
when Constraint_error =>
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters caused Constraint_Error ?");
-- I thought, because Null_Characters(1..0) = Null_Characters,
-- that the assignment would have succeeded, as it did
-- in the previous block.
end;
end;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Simpler Question (was Assigning to dereferenced null access variable)
2000-11-05 0:00 Assigning to dereferenced null access variable Vincent Marciante
@ 2000-11-07 0:00 ` Vincent Marciante
2000-11-07 0:00 ` Jean-Pierre Rosen
0 siblings, 1 reply; 9+ messages in thread
From: Vincent Marciante @ 2000-11-07 0:00 UTC (permalink / raw)
--Okay, I cut down the question to:
--
--Why don't both blocks in the following code behave similarly?
--I get the following output using OS/2 GNAT 3.12p
--
--The Null_Characters(1..0) assignment succeeded
--The Null_Characters assignment caused Constraint_Error
--
--If the above indicates a compiler defect then what is the
--correct behavior?
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Null_Assignments is
type Characters is array (Positive range <>) of Character;
Null_Characters : Characters(1..0);
type Reference is access Characters;
type Character_Sequence is
record
The_Characters : Reference;
end record;
Null_Sequence : Character_Sequence;
begin
begin
Null_Sequence.The_Characters(1..0) := Null_Characters(1..0);
Put_Line("The Null_Characters(1..0) assignment succeeded");
--OS/2 GNAT 3.12 succeeds
exception
when Constraint_Error =>
Put_Line("The Null_Characters(1..0) assignment caused
Constraint_Error");
end;
begin
Null_Sequence.The_Characters(1..0) := Null_Characters;
Put_Line("The Null_Characters assignment succeeded");
exception
when Constraint_Error =>
Put_Line("The Null_Characters assignment caused
Constraint_Error");
--OS/2 GNAT 3.12 raises Constraint_Error
end;
end;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Simpler Question (was Assigning to dereferenced null access variable)
2000-11-07 0:00 ` Jean-Pierre Rosen
@ 2000-11-07 0:00 ` Vincent Marciante
2000-11-08 4:20 ` Robert Dewar
0 siblings, 1 reply; 9+ messages in thread
From: Vincent Marciante @ 2000-11-07 0:00 UTC (permalink / raw)
Jean-Pierre Rosen wrote:
>
> "Vincent Marciante" <marciant@li.net> a �crit dans le message news:3A0847ED.49AF@li.net...
> >[...]
> > begin
> > Null_Sequence.The_Characters(1..0) := Null_Characters;
> > Put_Line("The Null_Characters assignment succeeded");
> > exception
> > when Constraint_Error =>
> > Put_Line("The Null_Characters assignment caused
> > Constraint_Error");
> > --OS/2 GNAT 3.12 raises Constraint_Error
> > end;
> > end;
> Null_Sequence.The_Characters is a null pointer, there is no array to point to. This is what causes Constraint_Error, nothing to do
> with the assignment.
>
> --
> ---------------------------------------------------------
> J-P. Rosen (Rosen.Adalog@wanadoo.fr)
> Visit Adalog's web site at http://pro.wanadoo.fr/adalog
I thought that null_sequence.the_characters being a null pointer
should always cause constraint_error. I will assume that you
mean that the fact that no constraint_error ocurred in the first
block (repeated below) indicates a compiler defect, so, I will send
a report to ACT. Thanks.
begin
Null_Sequence.The_Characters(1..0) := Null_Characters(1..0);
Put_Line("The Null_Characters(1..0) assignment succeeded");
--OS/2 GNAT 3.12 succeeds
exception
when Constraint_Error =>
Put_Line("The Null_Characters(1..0) assignment caused Constraint_Error");
end;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Simpler Question (was Assigning to dereferenced null access variable)
2000-11-07 0:00 ` Simpler Question (was Assigning to dereferenced null access variable) Vincent Marciante
@ 2000-11-07 0:00 ` Jean-Pierre Rosen
2000-11-07 0:00 ` Vincent Marciante
0 siblings, 1 reply; 9+ messages in thread
From: Jean-Pierre Rosen @ 2000-11-07 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 766 bytes --]
"Vincent Marciante" <marciant@li.net> a �crit dans le message news: 3A0847ED.49AF@li.net...
>[...]
> begin
> Null_Sequence.The_Characters(1..0) := Null_Characters;
> Put_Line("The Null_Characters assignment succeeded");
> exception
> when Constraint_Error =>
> Put_Line("The Null_Characters assignment caused
> Constraint_Error");
> --OS/2 GNAT 3.12 raises Constraint_Error
> end;
> end;
Null_Sequence.The_Characters is a null pointer, there is no array to point to. This is what causes Constraint_Error, nothing to do
with the assignment.
--
---------------------------------------------------------
J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://pro.wanadoo.fr/adalog
^ permalink raw reply [flat|nested] 9+ messages in thread
* GNAT for OS/2 (was Re: Simpler Question (was Assigning ...))
2000-11-08 4:20 ` Robert Dewar
2000-11-08 0:00 ` Vincent Marciante
@ 2000-11-08 0:00 ` Vincent Marciante
2000-11-10 1:52 ` tjerick
1 sibling, 1 reply; 9+ messages in thread
From: Vincent Marciante @ 2000-11-08 0:00 UTC (permalink / raw)
Robert Dewar wrote:
>
> No need, you are using a pretty old version of the compiler
> (3.12)
If glladly use a more recent public GNAT version if there was
one for OS/2 :) Might ACT make one available when GNAT gets
fully integrated into GCC 3.0? We OS/2ers are accustomed (and
greatful) for getting only every other public version ;)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Simpler Question (was Assigning to dereferenced null access variable)
2000-11-08 4:20 ` Robert Dewar
@ 2000-11-08 0:00 ` Vincent Marciante
2000-11-09 4:43 ` Robert Dewar
2000-11-08 0:00 ` GNAT for OS/2 (was Re: Simpler Question (was Assigning ...)) Vincent Marciante
1 sibling, 1 reply; 9+ messages in thread
From: Vincent Marciante @ 2000-11-08 0:00 UTC (permalink / raw)
Robert Dewar wrote:
> ... it is hard to imagine a real program being
> affected by this :-)
Actually, similar code was part of the unbounded string
components that are part of the original Booch Components!
Executing that code when compiled with another compiler
caused a constraint_error but not with GNAT.
P.S.
A corrected version of the string components is being prepared.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Simpler Question (was Assigning to dereferenced null access variable)
2000-11-07 0:00 ` Vincent Marciante
@ 2000-11-08 4:20 ` Robert Dewar
2000-11-08 0:00 ` Vincent Marciante
2000-11-08 0:00 ` GNAT for OS/2 (was Re: Simpler Question (was Assigning ...)) Vincent Marciante
0 siblings, 2 replies; 9+ messages in thread
From: Robert Dewar @ 2000-11-08 4:20 UTC (permalink / raw)
In article <3A089948.5979@li.net>,
Vincent Marciante <marciant@li.net> wrote:
> so, I will send a report to ACT
No need, you are using a pretty old version of the compiler
(3.12) and this problem of not checking for a constraint error
in the case of a null pointer pointing to nothing was fixed
a while ago (needless to say this was found in some peculiar
test program, it is hard to imagine a real program being
affected by this :-) Interestingly the ACATS/ACVC tests
did not test this particular case.
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Simpler Question (was Assigning to dereferenced null access variable)
2000-11-08 0:00 ` Vincent Marciante
@ 2000-11-09 4:43 ` Robert Dewar
0 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 2000-11-09 4:43 UTC (permalink / raw)
In article <3A0A24DF.38D9@li.net>,
Vincent Marciante <marciant@li.net> wrote:
> Robert Dewar wrote:
>
> > ... it is hard to imagine a real program being
> > affected by this :-)
>
> Actually, similar code was part of the unbounded string
> components that are part of the original Booch Components!
> Executing that code when compiled with another compiler
> caused a constraint_error but not with GNAT.
Yes, but what I am saying is that it is hard to believe that
any code *depends* on getting a constraint_error for assigning
nothing in such a case :-)
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GNAT for OS/2 (was Re: Simpler Question (was Assigning ...))
2000-11-08 0:00 ` GNAT for OS/2 (was Re: Simpler Question (was Assigning ...)) Vincent Marciante
@ 2000-11-10 1:52 ` tjerick
0 siblings, 0 replies; 9+ messages in thread
From: tjerick @ 2000-11-10 1:52 UTC (permalink / raw)
On Thu, 9 Nov 2000 03:46:49, Vincent Marciante <marciant@li.net>
wrote:
> Robert Dewar wrote:
> >
> > No need, you are using a pretty old version of the compiler
> > (3.12)
>
> If glladly use a more recent public GNAT version if there was
> one for OS/2 :) Might ACT make one available when GNAT gets
> fully integrated into GCC 3.0? We OS/2ers are accustomed (and
> greatful) for getting only every other public version ;)
Yes, I'd glady accept a new release of the OS/2 version on GNAT 3.1x.
Please?
Tim Erickson
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2000-11-10 1:52 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-05 0:00 Assigning to dereferenced null access variable Vincent Marciante
2000-11-07 0:00 ` Simpler Question (was Assigning to dereferenced null access variable) Vincent Marciante
2000-11-07 0:00 ` Jean-Pierre Rosen
2000-11-07 0:00 ` Vincent Marciante
2000-11-08 4:20 ` Robert Dewar
2000-11-08 0:00 ` Vincent Marciante
2000-11-09 4:43 ` Robert Dewar
2000-11-08 0:00 ` GNAT for OS/2 (was Re: Simpler Question (was Assigning ...)) Vincent Marciante
2000-11-10 1:52 ` tjerick
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox