[LTP] [PATCH v2] misc: rewrite crash02 test

Andrea Cervesato andrea.cervesato@suse.com
Tue Jul 1 14:53:46 CEST 2025


On 7/1/25 2:15 PM, Martin Doucha wrote:
>
> No, this is how to fix the algorithm:
>
> static long rand_number(void)
> {
>     unsigned long ret = 0;
>
>     for (int i = 0; i < sizeof(unsigned long); i++)
>         num |= ((rand() & 0xffUL) << (i * 8));
>
>     return ret;
> }
>
> This will generate random numbers in the full range from LONG_MIN to 
> LONG_MAX and without any undefined behavior. 

Why mixing up unsigned and signed? Also, as I mentioned in the previous 
comment, the more we use rand() and the higher is the chance we will 
move some data which is not going to be 0 or close to 0 neither, since 
every call will add a sequence of bits which hardly will be something 
really close to that value.

- Andrea



More information about the ltp mailing list