Update to libtiff-4.0.6 (#764)
[openjpeg.git] / thirdparty / libtiff / tif_lzw.c
index 58345f0ac2b9fa63acdbfec0fd5711eb6f3e4623..9b76dd03b3919ca24df4e994fdd35c349085ae16 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tif_lzw.c,v 1.47 2015-06-13 05:03:50 faxguy Exp $ */
+/* $Id: tif_lzw.c,v 1.49 2015-08-30 21:07:44 erouault Exp $ */
 
 /*
  * Copyright (c) 1988-1997 Sam Leffler
@@ -94,7 +94,7 @@ typedef struct {
        unsigned short  nbits;          /* # of bits/code */
        unsigned short  maxcode;        /* maximum code for lzw_nbits */
        unsigned short  free_ent;       /* next free entry in hash table */
-       long            nextdata;       /* next bits of i/o */
+       unsigned long   nextdata;       /* next bits of i/o */
        long            nextbits;       /* # of valid bits in lzw_nextdata */
 
        int             rw_mode;        /* preserve rw_mode from init */
@@ -367,7 +367,8 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
        unsigned char *bp;
        hcode_t code;
        int len;
-       long nbits, nextbits, nextdata, nbitsmask;
+       long nbits, nextbits, nbitsmask;
+        unsigned long nextdata;
        code_t *codep, *free_entp, *maxcodep, *oldcodep;
 
        (void) s;
@@ -836,13 +837,15 @@ LZWPreEncode(TIFF* tif, uint16 s)
        } else                                                  \
                rat = (incount<<8) / outcount;                  \
 }
+
+/* Explicit 0xff masking to make icc -check=conversions happy */
 #define        PutNextCode(op, c) {                                    \
        nextdata = (nextdata << nbits) | c;                     \
        nextbits += nbits;                                      \
-       *op++ = (unsigned char)(nextdata >> (nextbits-8));              \
+       *op++ = (unsigned char)((nextdata >> (nextbits-8))&0xff);               \
        nextbits -= 8;                                          \
        if (nextbits >= 8) {                                    \
-               *op++ = (unsigned char)(nextdata >> (nextbits-8));      \
+               *op++ = (unsigned char)((nextdata >> (nextbits-8))&0xff);       \
                nextbits -= 8;                                  \
        }                                                       \
        outcount += nbits;                                      \
@@ -872,7 +875,8 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
        hcode_t ent;
        long disp;
        long incount, outcount, checkpoint;
-       long nextdata, nextbits;
+       unsigned long nextdata;
+        long nextbits;
        int free_ent, maxcode, nbits;
        uint8* op;
        uint8* limit;
@@ -1034,7 +1038,7 @@ LZWPostEncode(TIFF* tif)
        register LZWCodecState *sp = EncoderState(tif);
        uint8* op = tif->tif_rawcp;
        long nextbits = sp->lzw_nextbits;
-       long nextdata = sp->lzw_nextdata;
+       unsigned long nextdata = sp->lzw_nextdata;
        long outcount = sp->enc_outcount;
        int nbits = sp->lzw_nbits;
 
@@ -1048,8 +1052,9 @@ LZWPostEncode(TIFF* tif)
                sp->enc_oldcode = (hcode_t) -1;
        }
        PutNextCode(op, CODE_EOI);
+        /* Explicit 0xff masking to make icc -check=conversions happy */
        if (nextbits > 0) 
-               *op++ = (unsigned char)(nextdata << (8-nextbits));
+               *op++ = (unsigned char)((nextdata << (8-nextbits))&0xff);
        tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata);
        return (1);
 }