Skip to content

Commit

Permalink
fix jl_gc_realloc_string size miscomputation
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed May 23, 2017
1 parent 8d4db9c commit df3cd1c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,8 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
return snew;
}
size_t newsz = sz + sizeof(size_t) + 1;
size_t offs = offsetof(bigval_t, header);
size_t offs = sizeof(bigval_t);
size_t oldsz = LLT_ALIGN(strsz + offs, JL_CACHE_BYTE_ALIGNMENT);
size_t allocsz = LLT_ALIGN(newsz + offs, JL_CACHE_BYTE_ALIGNMENT);
if (allocsz < sz) // overflow in adding offs, size was "negative"
jl_throw(jl_memory_exception);
Expand All @@ -2804,9 +2805,7 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
// the old pointer to be left alone if we can't grow in place.
// for now it's up to the caller to make sure there are no references to the
// old pointer.
bigval_t *newbig =
(bigval_t*)gc_managed_realloc_(ptls, hdr, allocsz, LLT_ALIGN(strsz+offs, JL_CACHE_BYTE_ALIGNMENT),
1, s, 0);
bigval_t *newbig = (bigval_t*)gc_managed_realloc_(ptls, hdr, allocsz, oldsz, 1, s, 0);
newbig->sz = allocsz;
newbig->age = 0;
gc_big_object_link(newbig, &ptls->heap.big_objects);
Expand Down

0 comments on commit df3cd1c

Please sign in to comment.