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

remaining signedness issue in Encode 1.88

Thread Next
From:
Craig A. Berry
Date:
February 25, 2003 21:50
Subject:
remaining signedness issue in Encode 1.88
Message ID:
a05200f12ba81fe9d6298@[172.16.52.1]
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);
        SvPOK_only(dst);
        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
mailto:craigberry@mac.com

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

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