delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/11/20:20:26

From: Maxximo <mssmsoft AT my-dejanews DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: ? array[n] or array[n+1] ?
Date: Tue, 11 May 1999 11:27:32 GMT
Organization: Deja.com - Share what you know. Learn what you don't.
Lines: 40
Message-ID: <7h946u$qhe$1@nnrp1.deja.com>
References: <37367f71 DOT 6271443 AT news DOT wanadoo DOT fr> <3736A098 DOT 55E268BE AT softhome DOT net> <373c0195 DOT 3902906 AT news DOT wanadoo DOT fr> <3737f542 DOT 0 AT nnrp1 DOT news DOT uk DOT psi DOT net>
NNTP-Posting-Host: 138.132.53.11
X-Article-Creation-Date: Tue May 11 11:27:32 1999 GMT
X-Http-User-Agent: Mozilla/3.04Gold (X11; I; OSF1 V4.0 alpha)
X-Http-Proxy: 1.0 x31.deja.com:80 (Squid/1.1.22) for client 138.132.53.11
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <3737f542 DOT 0 AT nnrp1 DOT news DOT uk DOT psi DOT net>,
  "Ya'qub" <rick AT nct-active DOT com> wrote:
> Also, out of curiosity, if you do overrun an array and the program has
> compiled without any warning or error, is there anything that can be
said
> about its execution? i.e. do we know what is going to happen when the
> program tries to access an element from the array beyond its length.
Thanks
> Regards,
> Ya'qub

Then, this is true for several Unix machine. I don't know if this is
true for a PC with Win* or DOS.
When a process (or program) tries to access an element from the array
beyond its length this can happen:

1) The array is located in the process stack: if the used index is
nearly the end of the array, you simply read (or write) a value from the
stack. This value is not predictable. If you read a value and test it,
your program can show an error, but if you WRITE a value, the result are
impredictable: you can overwrite a subroutine return address, the
address of a variable, the value of another stack variable and so on.
It's hard to find and solve this types of errors.
2) The array is located in main memory: you can overwrite another
variable stored in main memory.

In either case above, if the address that you read (or write) is out of
the stack or out of the main memory, Unix send a signal to your process
(SIGBUS or SIGSEGV). Normally, process abort and the S.O. make a core
dump of the process to investigate about the cause (using a debugger).
If you are able, you can trap a signal with signal().

Bye
Maxximo




--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019