Silence -Woverflow warning in arc4random.c
Commit Message
This patch fixes "integer overflow" warning in arc4random.c. It explicitly
casts REKEY_BASE macro to size_t. The existing code relies on an implicit
conversion to int and assumes that sizeof(int)=sizeof(size_t), which is
not always true.
2025-03-02 Jan Dubiec <jdx@o2.pl>
newlib/ChangeLog:
* libc/stdlib/arc4random.c (REKEY_BASE): Explicitly cast the macro
to size_t.
newlib/libc/stdlib/arc4random.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -50,11 +50,11 @@
#define RSBUFSZ (16*BLOCKSZ)
#if SIZE_MAX <= 65535
-#define REKEY_BASE ( 32*1024) /* NB. should be a power of 2 */
+#define REKEY_BASE ( (size_t)32*1024) /* NB. should be a power of 2 */
#elif SIZE_MAX <= 1048575
-#define REKEY_BASE ( 512*1024) /* NB. should be a power of 2 */
+#define REKEY_BASE ( (size_t)512*1024) /* NB. should be a power of 2 */
#else
-#define REKEY_BASE (1024*1024) /* NB. should be a power of 2 */
+#define REKEY_BASE ((size_t)1024*1024) /* NB. should be a power of 2 */
#endif
/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */