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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a88e582de42cdc9b X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news3.google.com!news2.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Bug in Ada (SuSe 10.2) ? Date: Fri, 22 Feb 2008 16:39:08 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <0_mdna0iHpIsCifaRVnzvQA@telenor.com> <47ba9867$0$21892$4f793bc4@news.tdc.fi> <3a281192-2744-4110-9fc1-90c155c9436b@d4g2000prg.googlegroups.com> <48277611-402f-4622-be05-6edddf6dd56a@o10g2000hsf.googlegroups.com> <624tcvF21i3nvU1@mid.individual.net> <2630d99b-1578-4d79-ac9c-64c00c203b77@e60g2000hsh.googlegroups.com> <69019a65-736e-48ee-bd9f-4c29cd7fc88f@72g2000hsu.googlegroups.com> <1203708110.6651.7.camel@K72> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-5 Content-Transfer-Encoding: 8bit X-Trace: pcls6.std.com 1203716348 11495 192.74.137.71 (22 Feb 2008 21:39:08 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 22 Feb 2008 21:39:08 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:VFvGwgh3Qu18BHRS3XMdawP4jxQ= Xref: g2news1.google.com comp.lang.ada:19997 Date: 2008-02-22T16:39:08-05:00 List-Id: Vadim Godunko writes: > On 22 ���, 22:21, Georg Bauhaus > wrote: >> On Fri, 2008-02-22 at 08:10 -0800, billjones6...@yahoo.com wrote: >> > Of course, the danger is only eliminated when this language-defined >> > check is fully implemented in standard mode. >> >> Here is another dangling pointer. The program is >> giving me results varying with compiler/OS. I didn't see >> how accessiblity checks could help in this case, but >> then maybe this is a different issue? >> >> with Ada.Unchecked_Deallocation; >> with Ada.Text_IO; >> >> procedure News3 is >> use Ada; >> >> type Int_Ptr is access Integer; >> Pointer: Int_Ptr; >> Dangling_Pointer: Int_Ptr; >> >> procedure Copy(Source: in out Int_Ptr; Target: out Int_Ptr) is >> procedure Oops is new Unchecked_Deallocation >> (Integer, Int_Ptr); >> begin >> Target := Source; >> Oops(Source); >> end Copy; >> >> begin >> Pointer := new Integer'(42); >> Copy(Pointer, Dangling_Pointer); >> >> Text_IO.Put_Line(Integer'image(Dangling_Pointer.all)); >> end News3; > > Unchecked_Deallocation never makes program less erroneous. In the > example it is safe to remove instantiation of Unchecked_Deallocation. > Allocated memory will be automatically reclaimed after control flow > leave News3 subprogram, independent does or doesn't it is a main > subprogram. An implementation is allowed to do such reclamation, but most do not, unless you add a Storage_Size or Storage_Pool clause. - Bob