diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-09-05 22:07:11 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-09-05 22:07:11 +0000 |
commit | c8d1a3475b419224c2d78c8803f50bc7d05443f8 (patch) | |
tree | 0c4e66a1588c546c37691ad66f6a7231cac608de /usr.bin/awk/run.c | |
parent | f8523e2ebf0b04630bfd32a637ecb1b32aa133b3 (diff) |
When rand() was made fully random, the return value of srand() was
also affected incorrectly. Noticed by Stephane Chazelas. This reverts
the return value of srand() to the old (not very useful) behaviour.
This also allows toggling rand() to strong/weak based upon whether
srand() is called without/with an argument.
Long discussion and work with millert
ok beck
Diffstat (limited to 'usr.bin/awk/run.c')
-rw-r--r-- | usr.bin/awk/run.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 83bebb8b52f..8f433ea7b7f 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.38 2014/12/19 19:28:55 deraadt Exp $ */ +/* $OpenBSD: run.c,v 1.39 2015/09/05 22:07:10 deraadt Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -1584,13 +1584,17 @@ 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: - if (!isrec(x)) { + if (isrec(x)) { /* no argument provided */ + u = time(NULL); + tmp = u; + srandom((unsigned int) u); + } else { u = getfval(x); tmp = u; srandom_deterministic((unsigned int) u); - u = srand_seed; - srand_seed = tmp; } + u = srand_seed; + srand_seed = tmp; break; case FTOUPPER: case FTOLOWER: |