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 Dec 30, 2017
1 parent 6e9476b commit 1cae074
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 @@ -794,3 +794,11 @@ end
@test nextind("\xf8\x9f\x98\x84", 1) == 2
@test next("\xf8\x9f\x98\x84z", 1)[2] == 2
@test nextind("\xf8\x9f\x98\x84z", 1) == 2

# 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 1cae074

Please sign in to comment.