[PATCH] Silence -Woverflow warning in arc4random.c
Jan Dubiec <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> newlib/ChangeLog: * libc/stdlib/arc4random.c (REKEY_BASE): Explicitly cast the macro to size_t.
integer-overflow.patch
(text/plain, 880 B)
newlib/libc/stdlib/arc4random.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/newlib/libc/stdlib/arc4random.c b/newlib/libc/stdlib/arc4random.c index 09a134c3b..bc5967892 100644 --- a/newlib/libc/stdlib/arc4random.c +++ b/newlib/libc/stdlib/arc4random.c @@ -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. */