develooper Front page | perl.perl5.porters | Postings from June 2015

Re: Coverity finding: shift by negative

Thread Previous | Thread Next
From:
Zefram
Date:
June 23, 2015 15:07
Subject:
Re: Coverity finding: shift by negative
Message ID:
20150623150657.GO23010@fysh.org
Ricardo Signes wrote:
>I think they're being treated in the same way, insofar as that way is "leave it
>mostly be."

No, shifting right by a whole lot currently does not yield zero.
Its undefined behaviour tends to be modulo-word-size in the same
situations as that for left shifts.

$ perl -lwe 'print ~0 >> 500'

>I think exposing the underlying representation would be a bit much.

We already expose the word size in defined shifting behaviour.

$ perl -lwe '$a=1;$t=0;while($a){$a<<=1;$t++;} print "word size $t"'

>"use integer" is meant to do that.

For shifts it doesn't really make a difference there, because shifting
is already an integer-specific operation.  "use integer" only affects
whether we treat the integer word as signed.

-zefram

Thread Previous | Thread Next


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