diff --git a/src/libbzip2.jl b/src/libbzip2.jl index 52ef24b..5736bac 100644 --- a/src/libbzip2.jl +++ b/src/libbzip2.jl @@ -21,7 +21,16 @@ mutable struct BZStream opaque::Ptr{Cvoid} end -bzalloc(::Ptr{Cvoid}, m::Cint, n::Cint) = ccall(:jl_malloc, Ptr{Cvoid}, (Cint,), m*n) +@assert typemax(Csize_t) ≥ typemax(Cint) + +function bzalloc(::Ptr{Cvoid}, m::Cint, n::Cint)::Ptr{Cvoid} + s, f = Base.Checked.mul_with_overflow(m, n) + if f || signbit(s) + C_NULL + else + ccall(:jl_malloc, Ptr{Cvoid}, (Csize_t,), s%Csize_t) + end +end bzfree(::Ptr{Cvoid}, p::Ptr{Cvoid}) = ccall(:jl_free, Cvoid, (Ptr{Cvoid},), p) function BZStream()