diff options
author | erouault <erouault> | 2015-08-30 20:49:55 +0000 |
---|---|---|
committer | erouault <erouault> | 2015-08-30 20:49:55 +0000 |
commit | cf82832e3e1f174697126f968a49e262de41621a (patch) | |
tree | 55583049712ae15b25d7365171e6b67daf4ff944 | |
parent | 21571fcc8d5f09701f154fb5d4f432a5c549c665 (diff) | |
download | libtiff-cf82832e3e1f174697126f968a49e262de41621a.tar.gz |
* libtiff/tif_fax3.c, libtiff/tif_lzw.c, libtiff/tif_predict.c:
add explicit masking with 0xff before casting
to unsigned char (make icc -check=conversions happy)
* libtiff/tif_predict.c: operate on unsigned datatypes when
computing/applying differences to avoid undefined behaviour of
signed types (C standard compliance)
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | libtiff/tif_fax3.c | 5 | ||||
-rw-r--r-- | libtiff/tif_lzw.c | 11 | ||||
-rw-r--r-- | libtiff/tif_predict.c | 72 |
4 files changed, 59 insertions, 39 deletions
@@ -1,3 +1,13 @@ +2015-08-30 Even Rouault <even.rouault at spatialys.com> + + * libtiff/tif_fax3.c, libtiff/tif_lzw.c, libtiff/tif_predict.c: + add explicit masking with 0xff before casting + to unsigned char (make icc -check=conversions happy) + + * libtiff/tif_predict.c: operate on unsigned datatypes when + computing/applying differences to avoid undefined behaviour of + signed types (C standard compliance) + 2015-08-30 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> * configure.ac: libtiff 4.0.5 released. diff --git a/libtiff/tif_fax3.c b/libtiff/tif_fax3.c index 2b2dccd0..bbe72555 100644 --- a/libtiff/tif_fax3.c +++ b/libtiff/tif_fax3.c @@ -1,4 +1,4 @@ -/* $Id: tif_fax3.c,v 1.74 2012-06-21 02:01:31 fwarmerdam Exp $ */ +/* $Id: tif_fax3.c,v 1.75 2015-08-30 20:49:55 erouault Exp $ */ /* * Copyright (c) 1990-1997 Sam Leffler @@ -442,8 +442,9 @@ _TIFFFax3fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) FILL(n, cp); run &= 7; } + /* Explicit 0xff masking to make icc -check=conversions happy */ if (run) - cp[0] |= 0xff00 >> run; + cp[0] = (unsigned char)((cp[0] | (0xff00 >> run))&0xff); } else cp[0] |= _fillmasks[run]>>bx; x += runs[1]; diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c index 58345f0a..ab04bbaa 100644 --- a/libtiff/tif_lzw.c +++ b/libtiff/tif_lzw.c @@ -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.48 2015-08-30 20:49:55 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -836,13 +836,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; \ @@ -1048,8 +1050,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); } diff --git a/libtiff/tif_predict.c b/libtiff/tif_predict.c index f93c6645..117c6062 100644 --- a/libtiff/tif_predict.c +++ b/libtiff/tif_predict.c @@ -1,4 +1,4 @@ -/* $Id: tif_predict.c,v 1.32 2010-03-10 18:56:49 bfriesen Exp $ */ +/* $Id: tif_predict.c,v 1.33 2015-08-30 20:49:55 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -239,12 +239,18 @@ PredictorSetupEncode(TIFF* tif) case 0: ; \ } +/* Remarks related to C standard compliance in all below functions : */ +/* - to avoid any undefined behaviour, we only operate on unsigned types */ +/* since the behaviour of "overflows" is defined (wrap over) */ +/* - when storing into the byte stream, we explicitly mask with 0xff so */ +/* as to make icc -check=conversions happy (not necessary by the standard) */ + static void horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) { tmsize_t stride = PredictorState(tif)->stride; - char* cp = (char*) cp0; + unsigned char* cp = (unsigned char*) cp0; assert((cc%stride)==0); if (cc > stride) { /* @@ -257,9 +263,9 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) cc -= 3; cp += 3; while (cc>0) { - cp[0] = (char) (cr += cp[0]); - cp[1] = (char) (cg += cp[1]); - cp[2] = (char) (cb += cp[2]); + cp[0] = (unsigned char) ((cr += cp[0]) & 0xff); + cp[1] = (unsigned char) ((cg += cp[1]) & 0xff); + cp[2] = (unsigned char) ((cb += cp[2]) & 0xff); cc -= 3; cp += 3; } @@ -271,10 +277,10 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) cc -= 4; cp += 4; while (cc>0) { - cp[0] = (char) (cr += cp[0]); - cp[1] = (char) (cg += cp[1]); - cp[2] = (char) (cb += cp[2]); - cp[3] = (char) (ca += cp[3]); + cp[0] = (unsigned char) ((cr += cp[0]) & 0xff); + cp[1] = (unsigned char) ((cg += cp[1]) & 0xff); + cp[2] = (unsigned char) ((cb += cp[2]) & 0xff); + cp[3] = (unsigned char) ((ca += cp[3]) & 0xff); cc -= 4; cp += 4; } @@ -282,7 +288,7 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) cc -= stride; do { REPEAT4(stride, cp[stride] = - (char) (cp[stride] + *cp); cp++) + (unsigned char) ((cp[stride] + *cp) & 0xff); cp++) cc -= stride; } while (cc>0); } @@ -302,7 +308,7 @@ swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) TIFFSwabArrayOfShort(wp, wc); wc -= stride; do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) + REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[stride] + (unsigned int)wp[0]) & 0xffff); wp++) wc -= stride; } while (wc > 0); } @@ -320,7 +326,7 @@ horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) if (wc > stride) { wc -= stride; do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) + REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[stride] + (unsigned int)wp[0]) & 0xffff); wp++) wc -= stride; } while (wc > 0); } @@ -456,7 +462,7 @@ horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); tmsize_t stride = sp->stride; - char* cp = (char*) cp0; + unsigned char* cp = (unsigned char*) cp0; assert((cc%stride)==0); @@ -466,33 +472,33 @@ horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) * Pipeline the most common cases. */ if (stride == 3) { - int r1, g1, b1; - int r2 = cp[0]; - int g2 = cp[1]; - int b2 = cp[2]; + unsigned int r1, g1, b1; + unsigned int r2 = cp[0]; + unsigned int g2 = cp[1]; + unsigned int b2 = cp[2]; do { - r1 = cp[3]; cp[3] = r1-r2; r2 = r1; - g1 = cp[4]; cp[4] = g1-g2; g2 = g1; - b1 = cp[5]; cp[5] = b1-b2; b2 = b1; + r1 = cp[3]; cp[3] = (unsigned char)((r1-r2)&0xff); r2 = r1; + g1 = cp[4]; cp[4] = (unsigned char)((g1-g2)&0xff); g2 = g1; + b1 = cp[5]; cp[5] = (unsigned char)((b1-b2)&0xff); b2 = b1; cp += 3; } while ((cc -= 3) > 0); } else if (stride == 4) { - int r1, g1, b1, a1; - int r2 = cp[0]; - int g2 = cp[1]; - int b2 = cp[2]; - int a2 = cp[3]; + unsigned int r1, g1, b1, a1; + unsigned int r2 = cp[0]; + unsigned int g2 = cp[1]; + unsigned int b2 = cp[2]; + unsigned int a2 = cp[3]; do { - r1 = cp[4]; cp[4] = r1-r2; r2 = r1; - g1 = cp[5]; cp[5] = g1-g2; g2 = g1; - b1 = cp[6]; cp[6] = b1-b2; b2 = b1; - a1 = cp[7]; cp[7] = a1-a2; a2 = a1; + r1 = cp[4]; cp[4] = (unsigned char)((r1-r2)&0xff); r2 = r1; + g1 = cp[5]; cp[5] = (unsigned char)((g1-g2)&0xff); g2 = g1; + b1 = cp[6]; cp[6] = (unsigned char)((b1-b2)&0xff); b2 = b1; + a1 = cp[7]; cp[7] = (unsigned char)((a1-a2)&0xff); a2 = a1; cp += 4; } while ((cc -= 4) > 0); } else { cp += cc - 1; do { - REPEAT4(stride, cp[stride] -= cp[0]; cp--) + REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0])&0xff); cp--) } while ((cc -= stride) > 0); } } @@ -503,7 +509,7 @@ horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); tmsize_t stride = sp->stride; - int16 *wp = (int16*) cp0; + uint16 *wp = (uint16*) cp0; tmsize_t wc = cc/2; assert((cc%(2*stride))==0); @@ -512,7 +518,7 @@ horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) wc -= stride; wp += wc - 1; do { - REPEAT4(stride, wp[stride] -= wp[0]; wp--) + REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[stride] - (unsigned int)wp[0]) & 0xffff); wp--) wc -= stride; } while (wc > 0); } @@ -523,7 +529,7 @@ horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); tmsize_t stride = sp->stride; - int32 *wp = (int32*) cp0; + uint32 *wp = (uint32*) cp0; tmsize_t wc = cc/4; assert((cc%(4*stride))==0); |