From: Leon Timmermans Date: Sun, 19 Jun 2016 18:35:39 +0000 (+0200) Subject: Fix off-by-one bug in ' to :: substitution X-Git-Tag: v0.17~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9f60da160aa978c8bb651127e83caf3681e50ca5;p=p5sagit%2FSub-Name.git Fix off-by-one bug in ' to :: substitution --- diff --git a/Name.xs b/Name.xs index 10a8cd2..6168073 100644 --- a/Name.xs +++ b/Name.xs @@ -67,24 +67,25 @@ subname(name, sub) end = s - 1; begin = ++s; if (seen_quote) - seen_quote++; + need_subst++; } else if (*s && s[-1] == '\'') { end = s - 1; begin = s; - seen_quote++; + if (seen_quote++) + need_subst++; } } s--; if (end) { SV* tmp; - if (seen_quote > 1) { - STRLEN length = end - nameptr + seen_quote; + if (need_subst) { + STRLEN length = end - nameptr + seen_quote - (*end == '\'' ? 1 : 0); char* left; int i, j; tmp = newSV(length); left = SvPVX(tmp); - for (i = 0, j = 0; j <= end - nameptr; ++i, ++j) { + for (i = 0, j = 0; j < end - nameptr; ++i, ++j) { if (nameptr[j] == '\'') { left[i] = ':'; left[++i] = ':'; @@ -93,7 +94,7 @@ subname(name, sub) left[i] = nameptr[j]; } } - stash = gv_stashpvn(left, i - 2, GV_ADD | utf8flag); + stash = gv_stashpvn(left, length, GV_ADD | utf8flag); SvREFCNT_dec(tmp); } else