summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorAndy Lester <andy@petdance.com>2006-04-15 19:14:23 -0500
committerSteve Peters <steve@fisharerojo.org>2006-04-16 05:24:04 +0000
commit01f6e8062d776f5a635aed599b0634d217fae39b (patch)
tree79efdd1ed468eb88b9aec78232a11ef74ad29a50 /pp.c
parent57ca3b03ba60ea2dbeab22177ddd931a23911c4a (diff)
downloadperl-01f6e8062d776f5a635aed599b0634d217fae39b.tar.gz
update to pp_complement() via Coverity
Message-ID: <20060416051423.GA17063@petdance.com> p4raw-id: //depot/perl@27836
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/pp.c b/pp.c
index b52be7c84b..a1f51aa6d0 100644
--- a/pp.c
+++ b/pp.c
@@ -2429,13 +2429,11 @@ PP(pp_complement)
if (SvUTF8(TARG)) {
/* Calculate exact length, let's not estimate. */
STRLEN targlen = 0;
- U8 *result;
- U8 *send;
STRLEN l;
UV nchar = 0;
UV nwide = 0;
+ U8 * const send = tmps + len;
- send = tmps + len;
while (tmps < send) {
const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV);
tmps += UTF8SKIP(tmps);
@@ -2449,30 +2447,37 @@ PP(pp_complement)
tmps -= len;
if (nwide) {
+ U8 *result;
+ U8 *p;
+
Newxz(result, targlen + 1, U8);
+ p = result;
while (tmps < send) {
const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV);
tmps += UTF8SKIP(tmps);
- result = uvchr_to_utf8_flags(result, ~c, UNICODE_ALLOW_ANY);
+ p = uvchr_to_utf8_flags(p, ~c, UNICODE_ALLOW_ANY);
}
- *result = '\0';
- result -= targlen;
+ *p = '\0';
sv_setpvn(TARG, (char*)result, targlen);
SvUTF8_on(TARG);
+ Safefree(result);
}
else {
+ U8 *result;
+ U8 *p;
+
Newxz(result, nchar + 1, U8);
+ p = result;
while (tmps < send) {
const U8 c = (U8)utf8n_to_uvchr(tmps, 0, &l, UTF8_ALLOW_ANY);
tmps += UTF8SKIP(tmps);
- *result++ = ~c;
+ *p++ = ~c;
}
- *result = '\0';
- result -= nchar;
+ *p = '\0';
sv_setpvn(TARG, (char*)result, nchar);
SvUTF8_off(TARG);
+ Safefree(result);
}
- Safefree(result);
SETs(TARG);
RETURN;
}