Home | History | Annotate | Download | only in stdlib
History log of /src/lib/libc/stdlib/_rand48.c
RevisionDateAuthorComments
 1.10  23-Feb-2020  kamil Change the previous cast from unsigned int to unsigned long

This code produces the same result and is consistent with the previous
lines. Only the least significant 16 bites (unsigned short) are meaningful.
 1.9  22-Feb-2020  kamil Avoid undefined behavior in the rand48(3) implementation

Instead of implicid promotion to signed int,
explicitly cast the arguments to unsigned int.

_rand48.c:53:27, signed integer overflow:
58989 * 58970 cannot be represented in type 'int'

_rand48.c:53:38, signed integer overflow:
-2093025904 + -1496809120 cannot be represented in type 'int'

_rand48.c:53:57, signed integer overflow:
57068 * 42787 cannot be represented in type 'int'

New and old code produce the same code as tested with:

#include <stdio.h>
#include <stdlib.h>

#define COUNT 1000 * 1000

int
main(void)
{
FILE *fp;
int i;

fp = fopen("numbers.txt", "w+");
if (!fp)
abort();

for(i = 0; i < COUNT; i++) {
fprintf(fp, "%f\n", drand48());
fprintf(fp, "%ld\n", lrand48());
fprintf(fp, "%ld\n", mrand48());
}

fclose(fp);

return 0;
}
 1.8  22-Feb-2020  kamil Improve readability of __dorand48()

Break long lines into shorter instructions per line.

No Functional Change.
 1.7  12-Jun-2005  lukem branches: 1.7.86;
Add missing __RCSID()
 1.6  20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.5  16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.4  09-Jan-1998  perry RCS Id Police.
 1.3  14-Oct-1993  jtc Rename intenral _rand_foo variables to __rand_foo, as _rand_foo is in the
user's namespace.
 1.2  13-Oct-1993  jtc Change _dorand48 to __dorand48, as _dorand48 is in the user's namespace.
 1.1  07-Oct-1993  brezak Rand48 routines from martin@ntkupc1.tuwien.ac.at (Martin Birgmeier)
 1.7.86.1  08-Apr-2020  martin Merge changes from current as of 20200406

RSS XML Feed