From: Nicholas Clark Date: Sat, 29 Dec 2007 19:50:27 +0000 (+0000) Subject: In sv_chop(), write sentinals over the part of the buffer that is X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=50af2e611e4aecf342d3df7e3a9c906c5174ca05;p=p5sagit%2Fp5-mst-13.2.git In sv_chop(), write sentinals over the part of the buffer that is thrown away, and verify that they are present in sv_backoff(). assert that we are being asked to chop off positive amounts of buffer. p4raw-id: //depot/perl@32778 --- diff --git a/sv.c b/sv.c index bb64eb9..bf8d503 100644 --- a/sv.c +++ b/sv.c @@ -1403,6 +1403,16 @@ Perl_sv_backoff(pTHX_ register SV *sv) assert(SvTYPE(sv) != SVt_PVAV); if (SvIVX(sv)) { const char * const s = SvPVX_const(sv); +#ifdef DEBUGGING + /* Validate the preceding buffer's sentinals to verify that no-one is + using it. */ + const U8 *p = (const U8*) s; + const U8 *const real_start = p - SvIVX(sv); + while (p > real_start) { + --p; + assert (*p == (U8)PTR2UV(p)); + } +#endif SvLEN_set(sv, SvLEN(sv) + SvIVX(sv)); SvPV_set(sv, SvPVX(sv) - SvIVX(sv)); SvIV_set(sv, 0); @@ -4215,6 +4225,7 @@ Perl_sv_chop(pTHX_ register SV *sv, register const char *ptr) /* Nothing to do. */ return; } + assert(ptr > SvPVX_const(sv)); SV_CHECK_THINKFIRST(sv); if (SvTYPE(sv) < SVt_PVIV) sv_upgrade(sv,SVt_PVIV); @@ -4238,6 +4249,18 @@ Perl_sv_chop(pTHX_ register SV *sv, register const char *ptr) SvCUR_set(sv, SvCUR(sv) - delta); SvPV_set(sv, SvPVX(sv) + delta); SvIV_set(sv, SvIVX(sv) + delta); +#ifdef DEBUGGING + { + /* Fill the preceding buffer with sentinals to verify that no-one is + using it. */ + U8 *p = (U8*) SvPVX(sv); + const U8 *const real_start = p - SvIVX(sv); + while (p > real_start) { + --p; + *p = (U8)PTR2UV(p); + } + } +#endif } /*