Skip to content

Commit 49e03d5

Browse files
committed
sv_grow - new allocs are at least a sensible size
We don't believe that the size of new buffers allocated via Perl_sv_grow should be rounded up, but with the new `expected_size` macro we can ensure that `newlen` is not smaller than the minimum possible allocation and is at least rounded up to the nearest PTRSIZE.
1 parent da662ca commit 49e03d5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sv.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,11 +1425,15 @@ Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen)
14251425
#ifndef PERL_UNWARANTED_CHUMMINESS_WITH_MALLOC
14261426

14271427
/* Don't round up on the first allocation, as odds are pretty good that
1428-
* the initial request is accurate as to what is really needed */
1428+
* the initial request is accurate as to what is really needed.
1429+
* However, do reflect our best understanding of the allocation size
1430+
* likely to result, so that SvLEN is as accurate as possible. */
14291431
if (SvLEN(sv)) {
14301432
STRLEN rounded = PERL_STRLEN_ROUNDUP(newlen);
14311433
if (rounded > newlen)
14321434
newlen = rounded;
1435+
} else {
1436+
newlen = expected_size(newlen);
14331437
}
14341438
#endif
14351439
if (SvLEN(sv) && s) {

0 commit comments

Comments
 (0)