• Paul Eggert's avatar
    random_r: do not crash if state is unaligned · 6979c258
    Paul Eggert authored
    Problem reported by Bruce Korb in:
    I reproduced the crash on 32-bit sparc with Oracle Studio 12.6
    with 'cc -O2 -xmemalign=8s'.
    * lib/random_r.c: Include string.h, for memcpy.
    (get_int32, set_int32): New functions.
    (__srandom_r, __initstate_r, __setstate_r, __random_r):
    Use them to avoid assumption that state pointer is aligned.
    (__random_r): Avoid integer overflow if INT_MAX == UINT32_MAX.
    * tests/test-random_r.c (test_failed): New function.
    (main): Use it, to test for alignment bugs.
To find the state of this project's repository at the time of any of these versions, check out the tags.