Skip to content

Commit 544694a

Browse files
vtjnashtkelman
authored andcommitted
fix jl_gc_realloc_string size miscomputation
fix #22021 (cherry picked from commit df3cd1c) ref #22044
1 parent 0b1e4ef commit 544694a

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
@@ -2334,7 +2334,8 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
23342334
return snew;
23352335
}
23362336
size_t newsz = sz + sizeof(size_t) + 1;
2337-
size_t offs = offsetof(bigval_t, header);
2337+
size_t offs = sizeof(bigval_t);
2338+
size_t oldsz = LLT_ALIGN(strsz + offs, JL_CACHE_BYTE_ALIGNMENT);
23382339
size_t allocsz = LLT_ALIGN(newsz + offs, JL_CACHE_BYTE_ALIGNMENT);
23392340
if (allocsz < sz) // overflow in adding offs, size was "negative"
23402341
jl_throw(jl_memory_exception);
@@ -2346,9 +2347,7 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
23462347
// the old pointer to be left alone if we can't grow in place.
23472348
// for now it's up to the caller to make sure there are no references to the
23482349
// old pointer.
2349-
bigval_t *newbig =
2350-
(bigval_t*)gc_managed_realloc_(ptls, hdr, allocsz, LLT_ALIGN(strsz+offs, JL_CACHE_BYTE_ALIGNMENT),
2351-
1, s, 0);
2350+
bigval_t *newbig = (bigval_t*)gc_managed_realloc_(ptls, hdr, allocsz, oldsz, 1, s, 0);
23522351
newbig->sz = allocsz;
23532352
newbig->age = 0;
23542353
gc_big_object_link(newbig, &ptls->heap.big_objects);

0 commit comments

Comments
 (0)