public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/710] New: initstate() does not save the current position of the previous state array
@ 2005-02-09 16:46 bergner at vnet dot ibm dot com
  2005-02-09 16:49 ` [Bug math/710] " bergner at vnet dot ibm dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bergner at vnet dot ibm dot com @ 2005-02-09 16:46 UTC (permalink / raw)
  To: glibc-bugs

The initstate() call does not save the current position of the previous state,
so if we switch back with setstate(), the sequence of random numbers generated
id different than if we had never called initstate/setstate.  This works on AIX,
MacOSX and FreeBSD.  The test case is simple:

Peter-Bergners-Computer:~ peter$ cat rand.c 
#include <stdlib.h>
#include <stdio.h>

int main (int argc, char **argv)
{
  int i;

  srandom(1);
  for (i=0; i < 10; i++) {
    printf("%d\n", (int)random());
    if (argc >= 2) {
      /* This should not perturb the random number sequence above */
      char *os, state[128];
      os = initstate (1, state, sizeof(state));
      setstate (os);
    }
  }
  return 0;
}

Expected result:
[bergner@otta bergner]$ gcc rand.c
[bergner@otta bergner]$ ./a.out 
1804289383
846930886
1681692777
1714636915
1957747793
424238335
719885386
1649760492
596516649
1189641421

Incorrect result:
[bergner@otta bergner]$ ./a.out 1
1804289383
940958272
77627160
1361779697
498448585
1782601122
919270010
55938899
1340091435
476760324

Correct result on MacOSX:

Peter-Bergners-Computer:~ peter$ uname -v
Darwin Kernel Version 7.7.0: Sun Nov  7 16:06:51 PST 2004;
root:xnu/xnu-517.9.5.obj~1/RELEASE_PPC 
Peter-Bergners-Computer:~ peter$ gcc rand.c 
Peter-Bergners-Computer:~ peter$ ./a.out 1
1804289383
846930886
1681692777
1714636915
1957747793
424238335
719885386
1649760492
596516649
1189641421

-- 
           Summary: initstate() does not save the current position of the
                    previous state array
           Product: glibc
           Version: 2.3.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
        AssignedTo: aj at suse dot de
        ReportedBy: bergner at vnet dot ibm dot com
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: linux-i686
  GCC host triplet: linux-i686
GCC target triplet: linux-i686


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/710] initstate() does not save the current position of the previous state array
  2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
@ 2005-02-09 16:49 ` bergner at vnet dot ibm dot com
  2005-02-10  9:40 ` cvs-commit at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bergner at vnet dot ibm dot com @ 2005-02-09 16:49 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From bergner at vnet dot ibm dot com  2005-02-09 16:49 -------
Created an attachment (id=400)
 --> (http://sources.redhat.com/bugzilla/attachment.cgi?id=400&action=view)
patch to __initstate_r

Here's a patch to the cvs version of stdlib/random_r.c:__initstate_r() that
saves the current position of the previous state array before switching to the
new state array.

-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/710] initstate() does not save the current position of the previous state array
  2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
  2005-02-09 16:49 ` [Bug math/710] " bergner at vnet dot ibm dot com
@ 2005-02-10  9:40 ` cvs-commit at gcc dot gnu dot org
  2005-02-16  4:19 ` roland at gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-02-10  9:40 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-02-10 09:40 -------
Subject: Bug 710

CVSROOT:	/cvs/glibc
Module name:	libc
Changes by:	roland@sources.redhat.com	2005-02-10 09:40:12

Modified files:
	stdlib         : Makefile random_r.c 
Added files:
	stdlib         : tst-random2.c 

Log message:
	2005-02-09  Jakub Jelinek  <jakub@redhat.com>
	
	[BZ #710]
	* stdlib/random_r.c (__initstate_r): Save old state.
	* stdlib/Makefile (tests): Add tst-random2.
	* stdlib/tst-random2.c: New test.
	Reported by Peter Bergner <bergner@vnet.ibm.com>.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/tst-random2.c.diff?cvsroot=glibc&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/Makefile.diff?cvsroot=glibc&r1=1.98&r2=1.99
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/random_r.c.diff?cvsroot=glibc&r1=1.18&r2=1.19



-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/710] initstate() does not save the current position of the previous state array
  2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
  2005-02-09 16:49 ` [Bug math/710] " bergner at vnet dot ibm dot com
  2005-02-10  9:40 ` cvs-commit at gcc dot gnu dot org
@ 2005-02-16  4:19 ` roland at gnu dot org
  2005-02-16 11:24 ` cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: roland at gnu dot org @ 2005-02-16  4:19 UTC (permalink / raw)
  To: glibc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |724
              nThis|                            |


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/710] initstate() does not save the current position of the previous state array
  2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
                   ` (2 preceding siblings ...)
  2005-02-16  4:19 ` roland at gnu dot org
@ 2005-02-16 11:24 ` cvs-commit at gcc dot gnu dot org
  2005-03-15 16:32 ` gbeauchesne at mandrakesoft dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-02-16 11:24 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-02-16 11:24 -------
Subject: Bug 710

CVSROOT:	/cvs/glibc
Module name:	libc
Branch: 	glibc-2_3-branch
Changes by:	roland@sources.redhat.com	2005-02-16 11:23:59

Modified files:
	stdlib         : Makefile random_r.c 
Added files:
	stdlib         : tst-random2.c 

Log message:
	2005-02-09  Jakub Jelinek  <jakub@redhat.com>
	
	[BZ #710]
	* stdlib/random_r.c (__initstate_r): Save old state.
	* stdlib/Makefile (tests): Add tst-random2.
	* stdlib/tst-random2.c: New test.
	Reported by Peter Bergner <bergner@vnet.ibm.com>.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/tst-random2.c.diff?cvsroot=glibc&only_with_tag=glibc-2_3-branch&r1=NONE&r2=1.1.4.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/Makefile.diff?cvsroot=glibc&only_with_tag=glibc-2_3-branch&r1=1.95.4.2&r2=1.95.4.3
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/random_r.c.diff?cvsroot=glibc&only_with_tag=glibc-2_3-branch&r1=1.18&r2=1.18.4.1



-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/710] initstate() does not save the current position of the previous state array
  2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
                   ` (3 preceding siblings ...)
  2005-02-16 11:24 ` cvs-commit at gcc dot gnu dot org
@ 2005-03-15 16:32 ` gbeauchesne at mandrakesoft dot com
  2005-03-15 16:33 ` gbeauchesne at mandrakesoft dot com
  2005-04-06  0:00 ` roland at gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: gbeauchesne at mandrakesoft dot com @ 2005-03-15 16:32 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From gbeauchesne at mandrakesoft dot com  2005-03-15 16:31 -------
This change causes initstate_r() to crash if provided with an initially empty
rand_data struct. What about the attached patch in addition?

-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/710] initstate() does not save the current position of the previous state array
  2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
                   ` (4 preceding siblings ...)
  2005-03-15 16:32 ` gbeauchesne at mandrakesoft dot com
@ 2005-03-15 16:33 ` gbeauchesne at mandrakesoft dot com
  2005-04-06  0:00 ` roland at gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: gbeauchesne at mandrakesoft dot com @ 2005-03-15 16:33 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From gbeauchesne at mandrakesoft dot com  2005-03-15 16:33 -------
Created an attachment (id=436)
 --> (http://sources.redhat.com/bugzilla/attachment.cgi?id=436&action=view)
patch against 2.3-branch 2005/03/15


-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/710] initstate() does not save the current position of the previous state array
  2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
                   ` (5 preceding siblings ...)
  2005-03-15 16:33 ` gbeauchesne at mandrakesoft dot com
@ 2005-04-06  0:00 ` roland at gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: roland at gnu dot org @ 2005-04-06  0:00 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From roland at gnu dot org  2005-04-05 23:59 -------
These changes are in the 2.3 branch as well as the trunk now.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://sources.redhat.com/bugzilla/show_bug.cgi?id=710

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

end of thread, other threads:[~2005-04-06  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-09 16:46 [Bug math/710] New: initstate() does not save the current position of the previous state array bergner at vnet dot ibm dot com
2005-02-09 16:49 ` [Bug math/710] " bergner at vnet dot ibm dot com
2005-02-10  9:40 ` cvs-commit at gcc dot gnu dot org
2005-02-16  4:19 ` roland at gnu dot org
2005-02-16 11:24 ` cvs-commit at gcc dot gnu dot org
2005-03-15 16:32 ` gbeauchesne at mandrakesoft dot com
2005-03-15 16:33 ` gbeauchesne at mandrakesoft dot com
2005-04-06  0:00 ` roland at gnu dot org

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).