bug: rand() not initialized

Joshua Nekl jnekl@zilog.com
Thu Oct 2 16:29:00 GMT 2008


newlib/libc/stdlib/rand.c 
	rand() calls _REENT_CHECK_RAND48

newlib/libc/include/sys/reent.h
	_REENT_CHECK_RAND48 calls _REENT_CHECK with _REENT_INIT_RAND48
	_REENT_CHECK calls _REENT_INIT_RAND48 after malloc(struct
_rand48)
	_REENT_INIT_RAND48 inits struct _rand48 *_r48 members except
_next_rand

	rand() calls _REENT_RAND_NEXT
	_REENT_RAND_NEXT returns unnitialized _next_rand

I know an uninitialized pseudo-random number may seem unimportant, but
...

1) repeated runs of the application should return the same pseudo-random
number
   in order for test results to be repeatable.
2) I'm using a 4-state simulator (verilog). 
   Since this variable is not initialized, it returns X's in my
simulation.
   X's multiplied by X's result in X's, and my simulation barfs.

Workaround -> call srand(1) first.

Regards, Josh



More information about the Newlib mailing list