comp.lang.ada
 help / color / mirror / Atom feed
From: mab@dst17.wdl.loral.com (Mark A Biggar)
Subject: Re: Memory overwrite?
Date: Wed, 18 Jan 1995 18:20:39 GMT
Date: 1995-01-18T18:20:39+00:00	[thread overview]
Message-ID: <1995Jan18.182039.7324@wdl.loral.com> (raw)
In-Reply-To: 3fe5cp$fnq@theopolis.orl.mmc.com

In article <3fe5cp$fnq@theopolis.orl.mmc.com> "Theodore E. Dennison" <dennison@escmail.mmc.orl.com> writes:
>wouters@ict.nl (Rick Wouters) wrote:
>> 	An Ada program which compiles correctly and which does not produce
>> 	run-time errors seems to overwrite memory.
>> 	No dynamic allocation is used nor are address types used.
>> 	Some records are defined with a length clause.
>> 	Does anyone know a reason which might result in overwriting memory
>> 	in a correctly compiled program?
>Tons. Most of the time when this happens it is because someone 
>screwed up a "for use at" clause or an "UNCHECKED_CONVERSION" from
>System.ADDRESS.

Actually the most likely reason for this is an uninitialized variable used
as an array index.  In Ada 83 the following code fragment can write anywhere
in memory and may well not raise an exception:

declare
	subtype index is integer range 1..10;
	type table is array (index) of integer;
	a: table;
	i: index;
begin
	a(i) := 0;
end;

An aggressive optimizer will eliminate any checks from the above code.
Even putting an explisit if statement around it doesn't help:

	if i in index then
		a(i) := 0;
	else
		raise constraint_error;
	end if;

because an aggressive optimizer will notice that the if test is always true
(in the absence of uninitialized variables, but uninitialized variables
are erroneous, which allow any behaviour, so it can ignore the problem)
and eliminate the test and the else branch completely.

Ada95 add the 'valid attribute to handle this problem.

--
Mark Biggar
mab@wdl.lroal.com











  parent reply	other threads:[~1995-01-18 18:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-01-13  8:35 Memory overwrite? Rick Wouters
     [not found] ` <3fe5cp$fnq@theopolis.orl.mmc.com>
1995-01-18 18:20   ` Mark A Biggar [this message]
1995-01-20  5:19     ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1995-01-24 12:47 R.A.L Williams
1995-01-25 16:31 ` Robert A Duff
1995-01-25 19:01 ` Tucker Taft
1995-01-25 21:24 ` Robert Dewar
1995-01-30 17:06 ` Theodore E. Dennison
1995-02-01 12:25   ` Robert Dewar
1995-01-26 13:05 R.A.L Williams
1995-01-27 14:01 ` Robert A Duff
1995-01-28 22:49   ` Robert Dewar
1995-01-30 14:16     ` Robert A Duff
1995-02-01 23:00       ` Matt Kennel
1995-01-28  5:54 ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox