8304836: Make MALLOC_MIN4 macro more robust

Reviewed-by: bchristi
This commit is contained in:
Naoto Sato 2023-04-24 15:37:35 +00:00
parent 2763cf14e6
commit f32adaf89f

View File

@ -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)))