This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Abnormal behavior of malloc in gcc-3.2.2
- From: Sandeep Kumar <sandeepksinha at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 20 Nov 2005 20:58:22 -0800
- Subject: Abnormal behavior of malloc in gcc-3.2.2
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 I tried, it works even beyond the limits of allocated area ...
I am using Glibc - 2.3.2-11.9 , gcc - 3.2.2
Is it a bug - malloc's implementation in Glibc.
Does malloc allocates a complete 4k page for certain size of memory asked for?
Infact, it gives a segmentation fault at 1681 location =>
p[1681]: 1681
Segmentation fault
Or is it using Heap area ?
--
Regards,
Sandeep