Skip to content

Commit

Permalink
fix #33974, wrong integer types used in jl_array_sizehint (#34005)
Browse files Browse the repository at this point in the history
(cherry picked from commit bc82c35)
  • Loading branch information
JeffBezanson authored and KristofferC committed Dec 3, 2019
1 parent 01ca795 commit 314093b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@ STATIC_INLINE void jl_array_shrink(jl_array_t *a, size_t dec)
if (a->flags.how == 0) return;

size_t elsz = a->elsize;
int newbytes = (a->maxsize - dec) * a->elsize;
int oldnbytes = (a->maxsize) * a->elsize;
size_t newbytes = (a->maxsize - dec) * a->elsize;
size_t oldnbytes = (a->maxsize) * a->elsize;
int isbitsunion = jl_array_isbitsunion(a);
if (isbitsunion) {
newbytes += a->maxsize - dec;
Expand Down Expand Up @@ -1107,7 +1107,7 @@ JL_DLLEXPORT void jl_array_sizehint(jl_array_t *a, size_t sz)
{
size_t n = jl_array_nrows(a);

int min = a->offset + a->length;
size_t min = a->offset + a->length;
sz = (sz < min) ? min : sz;

if (sz <= a->maxsize) {
Expand Down
11 changes: 11 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2657,3 +2657,14 @@ end
C = hcat(A, B)
@test typeof(C) == Array{Array{Float64,2},2}
end

# issue #33974
let n = 12000000, k = 257000000
# tests skipped since they use a lot of memory
@test_skip filter(x -> x[2] < 1.0, collect(enumerate(vcat(fill(0.5, n), fill(NaN, k)))))[end] == (n, 0.5)
@test_skip let v = collect(enumerate(vcat(fill(0.5, n), fill(NaN, k))))
resize!(v, n)
sizehint!(v, n)
v[end] == (n, 0.5)
end
end

0 comments on commit 314093b

Please sign in to comment.