Re: Abnormal behavior of malloc in gcc-3.2.2

2005-11-21 Thread Nicholas Nethercote
On Mon, 21 Nov 2005, Giovanni Bajo wrote: 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 ? No. For that to happen, you need some memory checker. GCC has -fmudflap, t

Re: Abnormal behavior of malloc in gcc-3.2.2

2005-11-21 Thread Giovanni Bajo
Sandeep Kumar <[EMAIL PROTECTED]> wrote: > 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 ? No. For that to happen, you need some memory checker. GCC has -fmudflap,

Re: Abnormal behavior of malloc in gcc-3.2.2

2005-11-20 Thread Sandeep Kumar
On 11/20/05, Andrew Pinski <[EMAIL PROTECTED]> wrote: > > > > Hi Everyone, > > > > int > > main () > > { > > int *p; > > int i; > > > > p = (int *) malloc (400 * sizeof (int)); > > for (i = 0; i < 512; i++) > > { > > p[i] = i; > > printf ("p[%d]: %d\n", i, p

Re: Abnormal behavior of malloc in gcc-3.2.2

2005-11-20 Thread Sandeep Kumar
On 11/20/05, Andrew Pinski <[EMAIL PROTECTED]> 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

Re: Abnormal behavior of malloc in gcc-3.2.2

2005-11-20 Thread Andrew Pinski
> > 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 segementatio

Re: Abnormal behavior of malloc in gcc-3.2.2

2005-11-20 Thread Andrew Pinski
> > Hi Everyone, > > int > main () > { > int *p; > int i; > > p = (int *) malloc (400 * sizeof (int)); > for (i = 0; i < 512; i++) > { > p[i] = i; > printf ("p[%d]: %d\n", i, p[i]); > } >return 0; > } > > The following code should terminate wit

Abnormal behavior of malloc in gcc-3.2.2

2005-11-20 Thread Sandeep Kumar
Hi Everyone, int main () { int *p; int i; p = (int *) malloc (400 * sizeof (int)); for (i = 0; i < 512; i++) { p[i] = i; printf ("p[%d]: %d\n", i, p[i]); } return 0; } The following code should terminate with Segmentation fault, right ? But when