summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-01-12 21:57:06 +0000
committerNicholas Clark <nick@ccl4.org>2008-01-12 21:57:06 +0000
commitd06445298904613950b0410a2f3b1125ab58c7b5 (patch)
tree92e2d7a0ef4e7d624ece57876c27798319fb2f07 /mg.c
parentea9222e0361fc718c049fb5b7d00308ef9b0978d (diff)
downloadperl-d06445298904613950b0410a2f3b1125ab58c7b5.tar.gz
Fix bug whereby length on a tied scalar that returned a UTF-8 value
would not be correct the first time. (And for the more pathological case, would be incorrect if the UTF-8-ness of the returned value changed.) p4raw-id: //depot/perl@32968
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/mg.c b/mg.c
index 41d283710f..b64a778099 100644
--- a/mg.c
+++ b/mg.c
@@ -308,12 +308,15 @@ Perl_mg_length(pTHX_ SV *sv)
}
}
- if (DO_UTF8(sv)) {
+ {
+ /* You can't know whether it's UTF-8 until you get the string again...
+ */
const U8 *s = (U8*)SvPV_const(sv, len);
- len = utf8_length(s, s + len);
+
+ if (DO_UTF8(sv)) {
+ len = utf8_length(s, s + len);
+ }
}
- else
- (void)SvPV_const(sv, len);
return len;
}