This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Abnormal behavior of malloc in gcc-3.2.2
On 11/20/05, Andrew Pinski <pinskia@physics.uc.edu> wrote:
> > > Second you are invoking undefined behavior by accessing passed the array bounds (or allocated
> > > bounds by malloc).
> >
> > I didnt get your point. I am allocating space only for 400 inregers
> > then as soon as in the loop if it crosses the value of 400 , it should
> > have given a segementation voilation ?
> > But is isint. Fine i agree this is not the job of the compiler, It
> > might never come into exesitence during the execution time, But Still
> > me must get a segmentation voilation by the operating system.
>
> No, no, no. You don't understand at all undefined behavior. Anything can happen.
> If you pass 400*sizeof(int) then it might work or it might not. It all depends on
> where the malloc allocates its memory. It could malloc it at the end of the page so
> that you will get a seg fault right away or after a while.
ya. Thanks a lot sir. I was really bugged with this problem since last
few days.
I am clear with it. I think i need to go through the basics again.
--
Regards,
Sandeep