TL;DR
A recent discussion highlights an inconsistency in the glibc implementation of the initstate function, which fails to return NULL on error as required by POSIX standards. This discrepancy can lead to unexpected behavior in applications relying on standard C compliance.
✦ Why It Matters
Check your code for assumptions about POSIX compliance in glibc to prevent runtime errors.
Key Takeaways
Full Summary
The initstate function is intended to initialize the state for random number generation in C. According to POSIX standards, it should return NULL when an error occurs, specifically when the provided state array is less than 8 bytes.
However, in the glibc implementation, calling initstate with an invalid state array does not return NULL, which contradicts the expected behavior. For example, when initializing with a state array of 1 byte, the function fails to return NULL, leading to confusion and potential bugs in software that assumes compliance with POSIX.
This inconsistency is documented in the RETURN VALUE section of the man page, which inaccurately describes the behavior. Developers should be aware of this discrepancy to avoid relying on glibc's implementation for POSIX compliance.
Related