Silence -Woverflow warning in arc4random.c

Message ID f75e65e1-ca3b-43e8-b0bb-28cf3818071a@o2.pl
State New
Headers
Series Silence -Woverflow warning in arc4random.c |

Commit Message

Jan Dubiec March 3, 2025, 12:15 a.m. UTC
  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(-)
  

Patch

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. */