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
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: sandeepksinha at gmail dot com (Sandeep Kumar)
- Cc: pinskia at physics dot uc dot edu (Andrew Pinski), gcc at gcc dot gnu dot org
- Date: Mon, 21 Nov 2005 00:19:01 -0500 (EST)
- Subject: Re: Abnormal behavior of malloc in gcc-3.2.2
> > 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.
--- Pinski