summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-07-11 17:17:37 +0100
committerFather Chrysostomos <sprout@cpan.org>2011-09-02 08:18:40 -0700
commitae38025c1617ab0606fba64e716a4820603b5f04 (patch)
tree3f7dbcb3b1f946603b8866df062fe6d424657711
parenta038578f463dd5e9617df9596d4b378791927d56 (diff)
downloadperl-ae38025c1617ab0606fba64e716a4820603b5f04.tar.gz
In Perl_sv_pos_u2b_flags and S_sv_pos_u2b_cached, return early for offset 0.
0 Unicode characters are always 0 octets long. Returning early ensures that any offsets we calculate later will always be non-zero. (cherry picked from commit 48f9cf718354a5326f9e9d40d02a063952160024, as this is a prerequisite for 3e2d381)
-rw-r--r--sv.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sv.c b/sv.c
index c80db98ff2..8a4e964554 100644
--- a/sv.c
+++ b/sv.c
@@ -6157,6 +6157,9 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start
assert (uoffset >= uoffset0);
+ if (!uoffset)
+ return 0;
+
if (!SvREADONLY(sv)
&& PL_utf8cache
&& (*mgp || (SvTYPE(sv) >= SVt_PVMG &&
@@ -6286,7 +6289,9 @@ Perl_sv_pos_u2b_flags(pTHX_ SV *const sv, STRLEN uoffset, STRLEN *const lenp,
MAGIC *mg = NULL;
boffset = sv_pos_u2b_cached(sv, &mg, start, send, uoffset, 0, 0);
- if (lenp) {
+ if (lenp
+ && *lenp /* don't bother doing work for 0, as its bytes equivalent
+ is 0, and *lenp is already set to that. */) {
/* Convert the relative offset to absolute. */
const STRLEN uoffset2 = uoffset + *lenp;
const STRLEN boffset2