From: Andy Lester Date: Sun, 16 Apr 2006 00:14:23 +0000 (-0500) Subject: update to pp_complement() via Coverity X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=01f6e8062d776f5a635aed599b0634d217fae39b;p=p5sagit%2Fp5-mst-13.2.git update to pp_complement() via Coverity Message-ID: <20060416051423.GA17063@petdance.com> p4raw-id: //depot/perl@27836 --- diff --git a/pp.c b/pp.c index b52be7c..a1f51aa 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; }