From: rafl Date: Sat, 4 Oct 2008 13:18:02 +0000 (+0000) Subject: Check if reallocation of PL_linestr is necessary before doing it. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c2cbbc7a0c7a113a65db74d376d83da833a5f25f;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. git-svn-id: http://dev.catalyst.perl.org/repos/bast/Devel-Declare/1.000/trunk@4876 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- 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);