develooper Front page | perl.perl5.porters | Postings from April 2014

[perl #121746] [PATCH] Coverity: (unintended) sign extension avoidance

Thread Previous
From:
Tony Cook via RT
Date:
April 28, 2014 04:06
Subject:
[perl #121746] [PATCH] Coverity: (unintended) sign extension avoidance
Message ID:
rt-4.0.18-14056-1398658007-1496.121746-15-0@perl.org
On Sat Apr 26 13:03:01 2014, jhi wrote:
> Attached.

Assuming I understand what Coverity is complaining about, shouldn't:

--- a/cpan/Encode/Unicode/Unicode.xs
+++ b/cpan/Encode/Unicode/Unicode.xs
@@ -80,7 +80,7 @@ enc_unpack(pTHX_ U8 **sp, U8 *e, STRLEN size, U8 endian)
 	if (endian == 'v')
 	    break;
 	v |= (*s++ << 16);
-	v |= (*s++ << 24);
+	v |= (UV)(*s++ << 24);
 	break;
     default:
 	croak("Unknown endian %c",(char) endian);

be:

+	v |= ((UV)*s++ << 24);

Though I think it's incorrect to complain here, *s is unsigned char, with the usual integer promotions that should become unsigned int and the value of the << operator is has the type of its left operand.

Tony

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=121746

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About