From f32adaf89fede5262db2cb5517fc649a87e0714d Mon Sep 17 00:00:00 2001 From: Naoto Sato Date: Mon, 24 Apr 2023 15:37:35 +0000 Subject: [PATCH] 8304836: Make MALLOC_MIN4 macro more robust Reviewed-by: bchristi --- src/java.base/share/native/libjava/jni_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.base/share/native/libjava/jni_util.c b/src/java.base/share/native/libjava/jni_util.c index 43a2ac5440a..1090170dff3 100644 --- a/src/java.base/share/native/libjava/jni_util.c +++ b/src/java.base/share/native/libjava/jni_util.c @@ -39,7 +39,7 @@ * negative, or the size is INT_MAX as the macro adds 1 * that overflows into negative value. */ -#define MALLOC_MIN4(len) ((unsigned)(len) >= INT_MAX ? \ +#define MALLOC_MIN4(len) ((len) >= INT_MAX || (len) < 0 ? \ NULL : \ ((char *)malloc((len) + 1 < 4 ? 4 : (len) + 1)))