From: Florian Ragwitz Date: Sat, 4 Oct 2008 13:18:02 +0000 (+0000) Subject: Check if reallocation of PL_linestr is necessary before doing it. X-Git-Tag: 0.005000~78 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce9a252bd409860532d2c919d25c53dfc2e2ec74;p=p5sagit%2FDevel-Declare.git Check if reallocation of PL_linestr is necessary before doing it. That way memory curruption caused by SvGROW on a PL_linestr comming from perl -e goes away. --- diff --git a/Declare.xs b/Declare.xs index 142a816..7bff0c9 100644 --- a/Declare.xs +++ b/Declare.xs @@ -118,10 +118,11 @@ void dd_set_linestr(pTHX_ char* new_value) { int new_len = strlen(new_value); char* old_linestr = SvPVX(PL_linestr); - SvGROW(PL_linestr, new_len); - - if (SvPVX(PL_linestr) != old_linestr) + if (SvLEN(PL_linestr) < new_len) { croak("forced to realloc PL_linestr for line %s, bailing out before we crash harder", SvPVX(PL_linestr)); + } + + SvGROW(PL_linestr, new_len); memcpy(SvPVX(PL_linestr), new_value, new_len+1);