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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a27864f6019f6e7f,start X-Google-Attributes: gid103376,public From: Vincent Marciante Subject: Assigning to dereferenced null access variable Date: 2000/11/05 Message-ID: <3A05A609.4CE6@li.net>#1/1 X-Deja-AN: 689982940 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@verio.net X-Trace: iad-read.news.verio.net 973448706 209.139.0.193 (Sun, 05 Nov 2000 18:25:06 GMT) Organization: Verio MIME-Version: 1.0 NNTP-Posting-Date: Sun, 05 Nov 2000 18:25:06 GMT Newsgroups: comp.lang.ada Date: 2000-11-05T00:00:00+00:00 List-Id: 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;