This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bug: rand() not initialized


Joshua Nekl wrote:
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.

Josh,

Thanks for catching this. A fix has been checked in to initialize _rand_next to 1.

-- Jeff J.
Regards, Josh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]