diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2011-04-20 22:28:40 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2011-04-20 22:28:40 +0000 |
commit | d2a0aead9c73d261c1eb30fe2d565b1052a6d2ed (patch) | |
tree | f6620d1b6d0bc3023d53353260c5fe63e4fea672 /usr.bin | |
parent | 1774f6ede164232540d2390ba2d6f0678c80fb5f (diff) |
Stash the old seed when srand() is called and use it as the return
value as per POSIX and the fine manual. Fix sent upstream to bwk.
OK deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/awk/run.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index f92dd503276..dbe0878469a 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.31 2010/06/13 17:58:19 millert Exp $ */ +/* $OpenBSD: run.c,v 1.32 2011/04/20 22:28:39 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -1477,6 +1477,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis char *p, *buf; Node *nextarg; FILE *fp; + static Awkfloat old_seed = 1; t = ptoi(a[0]); x = execute(a[1]); @@ -1580,11 +1581,12 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis u = (Awkfloat) (random() % RAND_MAX) / RAND_MAX; break; case FSRAND: + u = old_seed; if (isrec(x)) /* no argument provided, want arc4random() */ use_arc4 = 1; else { - u = getfval(x); - srandom((unsigned int) u); + old_seed = getfval(x); + srandom((unsigned int) old_seed); use_arc4 = 0; } break; |