File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -483,6 +483,12 @@ JL_DLLEXPORT jl_array_t *jl_pchar_to_array(const char *str, size_t len)
483483JL_DLLEXPORT jl_value_t * jl_array_to_string (jl_array_t * a )
484484{
485485 size_t len = jl_array_len (a );
486+ if (len == 0 ) {
487+ // this may seem like purely an optimization (which it also is), but it
488+ // also ensures that calling `String(a)` doesn't corrupt a previous
489+ // string also created the same way, where `a = StringVector(_)`.
490+ return jl_an_empty_string ;
491+ }
486492 if (a -> flags .how == 3 && a -> offset == 0 && a -> elsize == 1 &&
487493 (jl_array_ndims (a ) != 1 ||
488494 ((a -> maxsize + sizeof (void * ) + 1 <= GC_MAX_SZCLASS ) == (len + sizeof (void * ) + 1 <= GC_MAX_SZCLASS )))) {
Original file line number Diff line number Diff line change @@ -5298,6 +5298,16 @@ if Sys.WORD_SIZE == 64
52985298 @test_nowarn tester20360 ()
52995299end
53005300
5301+ # issue #39717
5302+ let a = Base. StringVector (2 ^ 17 )
5303+ b = String (a)
5304+ c = String (a)
5305+ GC. gc ()
5306+ @test sizeof (a) == 0
5307+ @test sizeof (b) == 2 ^ 17
5308+ @test sizeof (c) == 0
5309+ end
5310+
53015311@test_throws ArgumentError eltype (Bottom)
53025312
53035313# issue #16424, re-evaluating type definitions
You can’t perform that action at this time.
0 commit comments