public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* Uninitialised rng state
@ 2009-02-07  6:30 M Joonas Pihlaja
  2009-02-09 14:46 ` Brian Gough
  0 siblings, 1 reply; 2+ messages in thread
From: M Joonas Pihlaja @ 2009-02-07  6:30 UTC (permalink / raw)
  To: gsl-discuss


Hi gsl-l,

Valgrind complains about using uninitialised memory when 
accessing all gsl_rng_size() bytes of the gsl_rng_state() arrays 
returned by some rng types.

One example is mt19937 whose state has lots of unsigned longs 
followed by an int.  On a 64 bit machine the size of the state is 
5000 bytes of which 4 bytes are pad bytes inserted by the 
compiler due to the mix of int/ulong.  So later when I twiddle 
the state valgrind triggers on the uninitialised access. So I was 
wondering whether gsl_rng_alloc() really ought to calloc the 
state instead of mallocing it.  Thoughts?

As a workaround I'm currently clearing the entire state right 
after calling gsl_rng_alloc() and then calling gsl_rng_set(rng, 
gsl_rng_default_seed) right after.  This does quell valgrind, but 
is it a sane thing to do?

Cheers,

Joonas

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Uninitialised rng state
  2009-02-07  6:30 Uninitialised rng state M Joonas Pihlaja
@ 2009-02-09 14:46 ` Brian Gough
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Gough @ 2009-02-09 14:46 UTC (permalink / raw)
  To: M Joonas Pihlaja; +Cc: gsl-discuss

At Sat, 7 Feb 2009 08:30:41 +0200 (EET),
M Joonas Pihlaja wrote:
> One example is mt19937 whose state has lots of unsigned longs 
> followed by an int.  On a 64 bit machine the size of the state is 
> 5000 bytes of which 4 bytes are pad bytes inserted by the 
> compiler due to the mix of int/ulong.  So later when I twiddle 
> the state valgrind triggers on the uninitialised access. So I was 
> wondering whether gsl_rng_alloc() really ought to calloc the 
> state instead of mallocing it.  Thoughts?
> 
> As a workaround I'm currently clearing the entire state right 
> after calling gsl_rng_alloc() and then calling gsl_rng_set(rng, 
> gsl_rng_default_seed) right after.  This does quell valgrind, but 
> is it a sane thing to do?

Hello,

Valgrind 3.1 does not detect any errors for me when running the
gsl-1.12 rng test program on x86_64 with gcc 4.0.3 (apart from in the
fread and fwrite functions, where they're expected). 

 Can you send a full bug report to bug-gsl@gnu.org with the program,
complete valgrind error message, version of valgrind and gsl that you
use, and the compiler.  Thanks.

-- 
Brian Gough


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-09 14:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-07  6:30 Uninitialised rng state M Joonas Pihlaja
2009-02-09 14:46 ` Brian Gough

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).