From b65a483addbea8e331c9f63ca19f540db7007c4f Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Fri, 4 Oct 2024 21:11:44 -0400 Subject: [PATCH] use checked rather than overflow --- src/cgutils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 059a2951e53e8..eca23f06a9160 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -4513,13 +4513,13 @@ static jl_cgval_t emit_const_len_memorynew(jl_codectx_t &ctx, jl_datatype_t *typ if (isboxed) elsz = sizeof(void*); - __int128 nbytes = (__int128)nel * elsz; + size_t nbytes; + bool overflow = __builtin_mul_overflow(nel, elsz, &nbytes); if (isunion) { // an extra byte for each isbits union memory element, stored at m->ptr + m->length - nbytes += nel; + overflow |= __builtin_add_overflow(nbytes, nel, &nbytes); } - __int128 MAXINTVAL = (((size_t)-1)>>1); - if (nel >= MAXINTVAL || nbytes >= (__int128) MAXINTVAL) + if (overflow) emit_error(ctx, "invalid GenericMemory size: too large for system address width"); auto ct = get_current_task(ctx);