Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Jun 2005 15:40:58 -0700
From:      Mike Hunter <mhunter@ack.berkeley.edu>
To:        freebsd-hackers@freebsd.org
Subject:   unitialized memory is all zeros...why not garbage instead?
Message-ID:  <20050610224058.GA11336@malcolm.berkeley.edu>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050610224058.GA11336>