unitialized memory is all zeros...why not garbage instead?
Mike Hunter
mhunter at ack.berkeley.edu
Fri Jun 10 22:40:59 GMT 2005
Hey everybody,
I have a feeling that I'm missing something really obvious, but I'm having
trouble understanding why the following program:
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char * argv[])
{
void * ptr = malloc(65536);
size_t i;
for (i = 0; i < 65536; i++)
{
printf ("%x", *((unsigned char *)ptr + i));
if ((i % 16) == 0)
{
puts("\n");
}
}
return 0;
}
Never prints anything but "0"'s.
I ran less up to my hw.physmem by feeding it /dev/random and watching
top, and then ran the program, so I "know" there was tons of non-zero
bits in memory.
I'm curious because I am worried about information leaks between processes
on the same machine...did somebody decide to solve this problem while I
wasn't paying attention? :)
%gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.2 [FreeBSD] 20040728
%uname -a
FreeBSD mylabtop.berkeley.edu 5.4-STABLE FreeBSD 5.4-STABLE #1: Wed May
11 12:05:39 PDT 2005
More information about the freebsd-hackers
mailing list