Skip to content

Commit

Permalink
prevent modifying vector after in-place conversion to string
Browse files Browse the repository at this point in the history
part of #24388
  • Loading branch information
JeffBezanson committed Jan 2, 2018
1 parent 7a44c04 commit 7bce3b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)
if (jl_is_string(o)) {
a->flags.isshared = 1;
*(size_t*)o = jl_array_len(a);
a->nrows = 0;
#ifdef STORE_ARRAY_LEN
a->length = 0;
#endif
a->maxsize = 0;
return o;
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,11 @@ let s = "∀x∃y", u = codeunits(s)
@test_throws ErrorException (u[1] = 0x00)
@test collect(u) == b"∀x∃y"
end

# issue #24388
let v = unsafe_wrap(Vector{UInt8}, "abc")
s = String(v)
@test_throws BoundsError v[1]
push!(v, UInt8('x'))
@test s == "abc"
end

0 comments on commit 7bce3b1

Please sign in to comment.