rse 98/03/04 23:50:33
Modified: src/modules/standard mod_rewrite.c
Log:
Make sure the returned value of rand() is not greater then RAND_MAX on systems
like SunOS where we guessed the RAND_MAX value. This the way Ben requested but
without the "+1" because this actually leaded to an overflow warning under
compiletime and is not really needed because this is random number generating
functions where it doesn't count because of the additional bounding checks.
I've tested it now under FreeBSD 2.1.5 _and_ SunOS 4.1.3 and it both correctly
gives numbers between 1 and N when run with l=1 and h=N. Nothing more is
needed....
Revision Changes Path
1.82 +1 -1 apache-1.3/src/modules/standard/mod_rewrite.c
Index: mod_rewrite.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- mod_rewrite.c 1998/03/04 13:55:08 1.81
+++ mod_rewrite.c 1998/03/05 07:50:31 1.82
@@ -2796,7 +2796,7 @@
char buf[50];
rewrite_rand_init();
- sprintf(buf, "%.0f", (((double)rand()/RAND_MAX)*(h-l)));
+ sprintf(buf, "%.0f", (((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l)));
i = atoi(buf)+1;
if (i < l) i = l;
if (i > h) i = h;