Skip to content

Commit a78978e

Browse files
authored
Merge pull request #22044 from JuliaLang/jn/22021
fix jl_gc_realloc_string size miscomputation
2 parents 8d4db9c + df3cd1c commit a78978e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/gc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,7 +2792,8 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
27922792
return snew;
27932793
}
27942794
size_t newsz = sz + sizeof(size_t) + 1;
2795-
size_t offs = offsetof(bigval_t, header);
2795+
size_t offs = sizeof(bigval_t);
2796+
size_t oldsz = LLT_ALIGN(strsz + offs, JL_CACHE_BYTE_ALIGNMENT);
27962797
size_t allocsz = LLT_ALIGN(newsz + offs, JL_CACHE_BYTE_ALIGNMENT);
27972798
if (allocsz < sz) // overflow in adding offs, size was "negative"
27982799
jl_throw(jl_memory_exception);
@@ -2804,9 +2805,7 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
28042805
// the old pointer to be left alone if we can't grow in place.
28052806
// for now it's up to the caller to make sure there are no references to the
28062807
// old pointer.
2807-
bigval_t *newbig =
2808-
(bigval_t*)gc_managed_realloc_(ptls, hdr, allocsz, LLT_ALIGN(strsz+offs, JL_CACHE_BYTE_ALIGNMENT),
2809-
1, s, 0);
2808+
bigval_t *newbig = (bigval_t*)gc_managed_realloc_(ptls, hdr, allocsz, oldsz, 1, s, 0);
28102809
newbig->sz = allocsz;
28112810
newbig->age = 0;
28122811
gc_big_object_link(newbig, &ptls->heap.big_objects);

0 commit comments

Comments
 (0)