public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Is it a bug of gcc
@ 2004-01-03  6:39 dong jin
  2004-01-06 19:23 ` Jim Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: dong jin @ 2004-01-03  6:39 UTC (permalink / raw)
  To: gcc-bugs

Dear Sir:
  Happy new to you.
  when  I used gcc to compile my a very small program, which had been put a 
bug by me for a test.
when I finished compiling, and run it, It run well without any problem. but 
in fact it has very clear logical error. why? I really  appreciate your 
sharing this information.
I hope to get message "Segmentation fault", but nothing happened.
the follow is the little program.
********************************
#include <stdio.h>
int foo(int n){
     return 3*n;
}
int main (void){
    int i, *p;
    int tmp[5];  /*contain five int*/
    p= tmp;
     for (i = 0; i<10; i++){
        *p++ = foo(i);
    }
    return 0;
}

the CPU is: Pentium III, the version of gcc is GCC-3.3.2

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Is it a bug of gcc
  2004-01-03  6:39 Is it a bug of gcc dong jin
@ 2004-01-06 19:23 ` Jim Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Wilson @ 2004-01-06 19:23 UTC (permalink / raw)
  To: dong jin; +Cc: gcc-bugs

dong jin wrote:
> when I finished compiling, and run it, It run well without any problem. 
> but in fact it has very clear logical error. why? I really  appreciate 
> your sharing this information.
> I hope to get message "Segmentation fault", but nothing happened.

Writing past the end of an array does not generate a segmentation fault. 
  It just clobbers other memory locations.  If those clobbered memory 
locations contain pointers, and you try to derefence the pointers after 
they have been clobbered, then that may generate a segmentation fault.

The C language does not require array bounds checking, and most C 
compilers don't implement this by default.

The current gcc design makes it hard to do anything about this kind of 
problem, but there is development work addressing this, and hopefully 
future gcc versions will handle this better.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-01-06 19:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-03  6:39 Is it a bug of gcc dong jin
2004-01-06 19:23 ` Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).