restrict RANDOM to a positive 31-bit integer number, for use with modulo op

This commit is contained in:
tg 2006-08-18 18:48:26 +00:00
parent 79ba3570f0
commit 5ee451f98c
2 changed files with 5 additions and 5 deletions

4
main.c
View File

@ -6,7 +6,7 @@
#define EXTERN /* define EXTERNs in sh.h */
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.45 2006/08/18 13:40:15 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.46 2006/08/18 18:48:25 tg Exp $");
extern char **environ;
@ -21,7 +21,7 @@ static const char *initcoms[] = {
"typeset", "-r", "KSH_VERSION", NULL,
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-i", "PPID", "OPTIND=1", NULL,
"eval", "typeset -Ui RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"eval", "typeset -i RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"alias",
/* Standard ksh aliases */
"hash=alias -t", /* not "alias -t --": hash -r needs to work */

6
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.22 2006/08/18 13:40:16 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.23 2006/08/18 18:48:26 tg Exp $");
/*
* Variables
@ -917,10 +917,10 @@ getspec(struct tbl *vp)
#if HAVE_ARC4RANDOM
if (use_rand)
#endif
setint(vp, (long) (rand() & 0x7fff));
setint(vp, (long) (rand() & 0x7FFF));
#if HAVE_ARC4RANDOM
else
setint(vp, arc4random());
setint(vp, arc4random() & 0x7FFFFFFF);
#endif
vp->flag |= SPECIAL;
break;