Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can an Ada program create a Segment Fault?

198 views
Skip to first unread message

tmo...@bix.com

unread,
Feb 14, 1996, 3:00:00 AM2/14/96
to
Given all checks on, no unchecked programming, and no interfaces
to incorrect programming in other languages, can an Ada program,
even an incorrect one, cause things like Segment Faults?
I would think not. If yes, how?

Keith Thompson

unread,
Feb 14, 1996, 3:00:00 AM2/14/96
to

Yes. One easy way to do this is to use a buggy compiler (but that's
probably not what you had in mind).

Any erroneous execution can cause a segmentation fault (or any other
behavior, including the infamous nasal demons). For examples, look up
"erroneous" in the index of the Ada RM. Many cases of erroneous execution
involve check suppression, unchecked programming, or interfacing to
other languages, but not all of them do. For example, it's possible to
(attempt to) reference a record component after the record discriminant
has been changed, making the component non-existent, without invoking
a discriminant check. This can be done via aliasing.

--
Keith Thompson (The_Other_Keith) k...@thomsoft.com
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
"As God is my witness, I thought turkeys could fly." -- Arthur Carlson, WKRP

Nasser Abbasi

unread,
Feb 14, 1996, 3:00:00 AM2/14/96
to
In article <4frhtd$9...@news1.delphi.com>, tmo...@bix.com says...

>
>Given all checks on, no unchecked programming, and no interfaces
>to incorrect programming in other languages, can an Ada program,
>even an incorrect one, cause things like Segment Faults?
>I would think not. If yes, how?

Yes, I remember one time (a number of years ago) when I was sitting in
front of my VT100 terminal late at night, and I was drinking a nice fresh
made hot cup of coffe and programming on VAX/VMS using Ada83, oh, those
happy days :) , then during one run of the program I did get an access
violation, I almost flipped over and spilled the coffee I was holding
from the shock and surprise, since that was the first time I saw an
access violation from an Ada program, I recomposed my self, and with the
nice VMS debuger I found my problem. I do not remember seeing any more
access violations since that tragic day.

I really can't remember now how I managed to do, but I was able to !!

I agree with you, it is rare to get access violations from an Ada running
program, but it can happen.

Nasser
ps. If you like instead to see an example of access violations in C or
C++ instead, please let me know, I have lots of examples :)

Ted Dennison

unread,
Feb 14, 1996, 3:00:00 AM2/14/96
to
tmo...@bix.com wrote:
>
> Given all checks on, no unchecked programming, and no interfaces
> to incorrect programming in other languages, can an Ada program,
> even an incorrect one, cause things like Segment Faults?
> I would think not. If yes, how?


Sure. Trying to dereference a "garbage" access object on many systems
will give you this. It is common to make STORAGE_ERROR = "segmentation
violation".
--
T.E.D.
| Work - mailto:denn...@escmail.orl.mmc.com |
| Home - mailto:denn...@iag.net |
| URL - http://www.iag.net/~dennison |

Robert A Duff

unread,
Feb 14, 1996, 3:00:00 AM2/14/96
to
In article <4frhtd$9...@news1.delphi.com>, <tmo...@bix.com> wrote:
>Given all checks on, no unchecked programming, and no interfaces
>to incorrect programming in other languages, can an Ada program,
>even an incorrect one, cause things like Segment Faults?
>I would think not. If yes, how?

One could reasonably define "unchecked programming" to be "anything that
can cause things like segmentation faults". What's your definition?

Look up "erroneous" in the index of the RM. Anything that's erroneous
can cause seg faults (or any other good or bad behavior). For example,
you might not consider use of variables shared by multiple tasks to be
"unchecked", but doing it wrong can cause seg faults.

- Bob

Robert A Duff

unread,
Feb 14, 1996, 3:00:00 AM2/14/96
to
In article <4frrpf$r...@qualcomm.com>,

Nasser Abbasi <nab...@qualcomm.com> wrote:
>I really can't remember now how I managed to do, but I was able to !!

In Ada 83, it's possible to get that from an uninitialized variable.
E.g.:

A: array (Integer range 1..10) of Integer;
I: Integer range 1..10;
A(I) := 99; -- Wrong.

where I is uninitialized.

This hole is plugged in Ada 95 -- you won't get a seg fault. (You
might, however, get a wrong answer!)

- Bob

Mike Bishop

unread,
Feb 14, 1996, 3:00:00 AM2/14/96
to
tmo...@bix.com wrote:
>
> Given all checks on, no unchecked programming, and no interfaces
> to incorrect programming in other languages, can an Ada program,
> even an incorrect one, cause things like Segment Faults?
> I would think not. If yes, how?

I have personally experienced segmentation faults in Ada 83 using the
SunAda compiler. The other respondents to this question have given good
examples of what might cause a segmentation fault. In my case, it has
happened when I've dealt with large, pointer-based data structures. It
has had nothing to do with the compiler or the Unix OS, but the lousy
job I did implementing the data structure :-)

--
| Mike Bishop | How come they can make a potato chip in |
| mbi...@ghgcorp.com | one second, but it takes us months to |
| | develop software? - Dilbert's boss |

Ken & Virginia Garlington

unread,
Feb 15, 1996, 3:00:00 AM2/15/96
to
tmo...@bix.com wrote:
>
> Given all checks on, no unchecked programming, and no interfaces
> to incorrect programming in other languages, can an Ada program,
> even an incorrect one, cause things like Segment Faults?
> I would think not. If yes, how?

I'm not really sure what a segment fault entails, but here's some
guesses:

Compiler code generation error?

An exception propagated out of the environment task? (for some
compilers, maybe...)

Use of Chapter 13-ish features other than interfaces to other languages
(e.g., mapping an object to an illegal address)?

Robert I. Eachus

unread,
Feb 16, 1996, 3:00:00 AM2/16/96
to
In article <4frhtd$9...@news1.delphi.com> tmo...@bix.com writes:

> Given all checks on, no unchecked programming, and no interfaces
> to incorrect programming in other languages, can an Ada program,
> even an incorrect one, cause things like Segment Faults? I would
> think not. If yes, how?

Stack overflow is certainly a possibility, but I would expect the
run-time to change the segment fault into a Storage_Error exception.

Any erroneous program (in Ada 83) could cause a segment fault.
The most common cause of erroneousness is to reference an
uninitialized variable. (Good compilers will warn you or raise
Program_Error.) The most common way to cause a segment fault
is to do this in an array subscript on the left-hand side of an
assignment statement.


--

Robert I. Eachus

with Standard_Disclaimer;
use Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...

0 new messages