Skip to content

Commit

Permalink
Warn about negative size in array construction (JuliaLang#56262)
Browse files Browse the repository at this point in the history
After this,
```julia
julia> zeros(-1)
ERROR: ArgumentError: invalid GenericMemory size: the number of elements is either negative or too large for system address width
[...]
```
The error message is updated to warn about possible negative sizes when
creating arrays.

Fixes JuliaLang#55446
  • Loading branch information
jishnub authored Oct 21, 2024
1 parent 6d7e29f commit 11ef8eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/genericmemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jl_genericmemory_t *_new_genericmemory_(jl_value_t *mtype, size_t nel, int8_t is
prod += nel;
}
if (nel >= MAXINTVAL || prod >= (wideint_t) MAXINTVAL)
jl_exceptionf(jl_argumenterror_type, "invalid GenericMemory size: too large for system address width");
jl_exceptionf(jl_argumenterror_type, "invalid GenericMemory size: the number of elements is either negative or too large for system address width");
size_t tot = (size_t)prod + LLT_ALIGN(sizeof(jl_genericmemory_t),JL_SMALL_BYTE_ALIGNMENT);

int pooled = tot <= GC_MAX_SZCLASS;
Expand Down

0 comments on commit 11ef8eb

Please sign in to comment.