www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/11/11:10:21

From: "Ya'qub" <rick AT nct-active DOT com>
Newsgroups: comp.os.msdos.djgpp
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> <7h946u$qhe$1 AT nnrp1 DOT deja DOT com>
Subject: Re: ? array[n] or array[n+1] ?
Date: Tue, 11 May 1999 14:45:09 +0100
Lines: 51
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
NNTP-Posting-Host: 193.123.236.199
Message-ID: <37383391.0@nnrp1.news.uk.psi.net>
X-Trace: 11 May 1999 14:41:37 GMT, 193.123.236.199
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Greetings,
    Thanks for the information. On second thoughts, I realise that it was
probably silly of me to expect the compiler to detect that kind of bug
because it's probably only at run time that accessing an element beyond the
array length will actually be detected, right?
Regards,
Ya'qub

Maxximo <mssmsoft AT my-dejanews DOT com> wrote in message
news:7h946u$qhe$1 AT nnrp1 DOT deja 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