public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* problem with malloc in gcc-3.2.2
@ 2005-11-20  9:20 Sandeep Kumar
  0 siblings, 0 replies; only message in thread
From: Sandeep Kumar @ 2005-11-20  9:20 UTC (permalink / raw)
  To: gcc-bugs

 Hi all,

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-11-20  9:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-20  9:20 problem with malloc in gcc-3.2.2 Sandeep Kumar

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).