From 5ee451f98ca78a2e087cfa43fa74407205884a26 Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 18 Aug 2006 18:48:26 +0000 Subject: [PATCH] restrict RANDOM to a positive 31-bit integer number, for use with modulo op --- main.c | 4 ++-- var.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 0ccec64..f854302 100644 --- a/main.c +++ b/main.c @@ -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 */ diff --git a/var.c b/var.c index d07f22c..9e92847 100644 --- a/var.c +++ b/var.c @@ -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;