Skip to content

Commit

Permalink
use checked rather than overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed Oct 5, 2024
1 parent 294ae68 commit b65a483
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b65a483

Please sign in to comment.