Mail Archives: djgpp/1999/05/11/11:10:21
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 -