develooper Front page | perl.perl5.porters | Postings from February 2003

remaining signedness issue in Encode 1.88

Thread Next
Craig A. Berry
February 25, 2003 21:50
remaining signedness issue in Encode 1.88
Message ID:
With bleadperl, my C compiler complains about a line in 
encode_method() like so:

    if (slen <= 0){
%CC-I-QUESTCOMPARE, In this statement, the unsigned expression "slen" is being compared with a relational operator to a constant whose value is not greater than zero.  This might not be what you intended.
at line number 85 in file D0:[CRAIG.PERL.EXT.ENCODE]Encode.xs;1

That's with Compaq C V6.5-001 on OpenVMS Alpha V7.3-1.  Here's a bit 
more context:

    if (offset) {
      s += *offset;
      slen -= *offset;
      tlen = slen;

    if (slen <= 0){
        SvCUR_set(dst, 0);
        goto ENCODE_END;

If *offset is ever larger than slen when "slen -= *offset" is 
calculated, then slen (because it's unsigned) will wrap around and 
become a large positive value.  In the words of the compiler, "this 
might not be what you intended."  I don't understand the code well 
enough to know if the offset can ever be larger than the length, but 
it seems like it would be a good idea to protect against that even if 
it's not supposed to happen.
Craig A. Berry

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About