summaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2012-11-12 16:43:12 -0700
committerKarl Williamson <public@khwilliamson.com>2012-11-14 10:08:09 -0700
commitca9fab4684db1c2d435d11b9339f25cf4a8d3fba (patch)
tree731f1d7a566dd835e5809d3d70104a87e37d00da /utf8.c
parent750da83817c1e4f89d6495fec7275f6ae3981632 (diff)
downloadperl-ca9fab4684db1c2d435d11b9339f25cf4a8d3fba.tar.gz
utf8.c: Don't copy a buffer to itself
memcpy(), which is what Copy() resolves to, is not supposed to handle the possibility of overlapping source and destination. In some cases in this code, the source and destination pointers are identical. What should happen then is a no-op, so just don't do the copy in that case. If the ptrs aren't identical, they won't otherwise overlap, so the Copy() is valid except for when they are identical.
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/utf8.c b/utf8.c
index 3ee9f2dc44..322bc46f61 100644
--- a/utf8.c
+++ b/utf8.c
@@ -2366,7 +2366,9 @@ Perl_to_utf8_case(pTHX_ const U8 *p, U8* ustrp, STRLEN *lenp,
/* Here, there was no mapping defined, which means that the code point maps
* to itself. Return the inputs */
len = UTF8SKIP(p);
- Copy(p, ustrp, len, U8);
+ if (p != ustrp) { /* Don't copy onto itself */
+ Copy(p, ustrp, len, U8);
+ }
if (lenp)
*lenp = len;