From 13b1a72a3a71a565763be8af312bf3090182cc77 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 21 Dec 2017 23:18:32 -0500 Subject: [PATCH] prevent modifying vector after in-place conversion to string part of #24388 --- src/array.c | 5 +++++ test/strings/basic.jl | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/array.c b/src/array.c index 6135704f8e7dd..f42b8cc36f517 100644 --- a/src/array.c +++ b/src/array.c @@ -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; } } diff --git a/test/strings/basic.jl b/test/strings/basic.jl index 385d8986d046d..831474bee1f46 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -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