On Mon, 6 Dec 1999, Mark Hattarki wrote:
>
> Ok, I found out something weird today and I have to share the fsck'd
> upness of it. Can someone tell me why the following code _doesn't_ crash?
> (a trivia question :)
% gcc -o a a.c -lefence
% ./a
Electric Fence 2.0.5 Copyright (C) 1987-1998 Bruce Perens.
The value of p is 2
Segmentation fault
Just because it doesn't crash doesn't mean you are doing a good
job. You didn't get a Segmentation violation because your malloc routine
is allocating an entire page of memory at a time, not just one word. Look
at the source to your malloc routine, and try running this.
#include <stdio.h>
#include <stdlib.h>
int
main()
{
int i = 0;
int *p = NULL;
p = malloc (sizeof (int));
while (1)
{
printf ("i = %d\n", i);
*(p + i++) = 0;
}
return 0;
}
Adam
---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]