From 39fa8a04ee96853ab4cc8e51ca14bec7dfb570fb Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Wed, 3 Feb 2021 10:41:47 +0000 Subject: Add TIFF_SIZE_FORMAT for portable use of %z MinGW64 does support %z, but it issues a compiler warning. --- libtiff/tif_config.h.cmake.in | 9 +++++++++ libtiff/tif_config.h.in | 11 ++++++++++- libtiff/tif_lzma.c | 2 +- libtiff/tif_webp.c | 2 +- tools/rgb2ycbcr.c | 2 +- tools/tiff2pdf.c | 10 +++++----- tools/tiff2rgba.c | 4 ++-- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libtiff/tif_config.h.cmake.in b/libtiff/tif_config.h.cmake.in index 2b65d243..44d1240f 100644 --- a/libtiff/tif_config.h.cmake.in +++ b/libtiff/tif_config.h.cmake.in @@ -134,10 +134,19 @@ # endif #endif +#if !defined(__MINGW32__) +# define TIFF_SIZE_FORMAT "zu" +#endif #if SIZEOF_SIZE_T == 8 # define TIFF_SSIZE_FORMAT PRId64 +# if defined(__MINGW32__) +# define TIFF_SIZE_FORMAT PRIu64 +# endif #elif SIZEOF_SIZE_T == 4 # define TIFF_SSIZE_FORMAT PRId32 +# if defined(__MINGW32__) +# define TIFF_SIZE_FORMAT PRIu32 +# endif #else # error "Unsupported size_t size; please submit a bug report" #endif diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in index 6a543463..b15b2b04 100644 --- a/libtiff/tif_config.h.in +++ b/libtiff/tif_config.h.in @@ -150,10 +150,19 @@ /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES +#if !defined(__MINGW32__) +# define TIFF_SIZE_FORMAT "zu" +#endif #if SIZEOF_SIZE_T == 8 # define TIFF_SSIZE_FORMAT PRId64 +# if defined(__MINGW32__) +# define TIFF_SIZE_FORMAT PRIu64 +# endif #elif SIZEOF_SIZE_T == 4 # define TIFF_SSIZE_FORMAT PRId32 +# if defined(__MINGW32__) +# define TIFF_SIZE_FORMAT PRIu32 +# endif #else # error "Unsupported size_t size; please submit a bug report" -#endif \ No newline at end of file +#endif diff --git a/libtiff/tif_lzma.c b/libtiff/tif_lzma.c index a5770569..fc046475 100644 --- a/libtiff/tif_lzma.c +++ b/libtiff/tif_lzma.c @@ -213,7 +213,7 @@ LZMADecode(TIFF* tif, uint8_t* op, tmsize_t occ, uint16_t s) } while (sp->stream.avail_out > 0); if (sp->stream.avail_out != 0) { TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %"PRIu32" (short %zu bytes)", + "Not enough data at scanline %"PRIu32" (short %"TIFF_SIZE_FORMAT" bytes)", tif->tif_row, sp->stream.avail_out); return 0; } diff --git a/libtiff/tif_webp.c b/libtiff/tif_webp.c index 31412c84..50ffdce6 100644 --- a/libtiff/tif_webp.c +++ b/libtiff/tif_webp.c @@ -79,7 +79,7 @@ int TWebPDatasetWriter(const uint8_t* data, size_t data_size, if ( (tif->tif_rawcc + (tmsize_t)data_size) > tif->tif_rawdatasize ) { TIFFErrorExt(tif->tif_clientdata, module, - "Buffer too small by %zu bytes.", + "Buffer too small by %"TIFF_SIZE_FORMAT" bytes.", (size_t) (tif->tif_rawcc + data_size - tif->tif_rawdatasize)); return 0; } else { diff --git a/tools/rgb2ycbcr.c b/tools/rgb2ycbcr.c index de23594b..0407cd69 100644 --- a/tools/rgb2ycbcr.c +++ b/tools/rgb2ycbcr.c @@ -313,7 +313,7 @@ tiffcvt(TIFF* in, TIFF* out) "raster buffer"); if (raster == 0) { TIFFError(TIFFFileName(in), - "Failed to allocate buffer (%zu elements of %zu each)", + "Failed to allocate buffer (%"TIFF_SIZE_FORMAT" elements of %"TIFF_SIZE_FORMAT" each)", pixel_count, sizeof(uint32_t)); return (0); diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c index 4cdf0f90..7d0ab678 100644 --- a/tools/tiff2pdf.c +++ b/tools/tiff2pdf.c @@ -955,7 +955,7 @@ T2P* t2p_init() if(t2p==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %zu bytes of memory for t2p_init", + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for t2p_init", sizeof(T2P)); return( (T2P*) NULL ); } @@ -1079,7 +1079,7 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ if(t2p->tiff_pages==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %zu bytes of memory for tiff_pages array, %s", + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for tiff_pages array, %s", sizeof(T2P_PAGE) * directorycount, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -1090,7 +1090,7 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ if(t2p->tiff_tiles==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %zu bytes of memory for tiff_tiles array, %s", + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for tiff_tiles array, %s", sizeof(T2P_TILES) * directorycount, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -1263,7 +1263,7 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ if( t2p->tiff_tiles[i].tiles_tiles == NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %zu bytes of memory for t2p_read_tiff_init, %s", + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for t2p_read_tiff_init, %s", sizeof(T2P_TILE) * t2p->tiff_tiles[i].tiles_tilecount, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -5558,7 +5558,7 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){ if(t2p->pdf_xrefoffsets==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %zu bytes of memory for t2p_write_pdf", + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for t2p_write_pdf", sizeof(uint32_t) * t2p->pdf_xrefcount); t2p->t2p_error = T2P_ERR_ERROR; return(written); diff --git a/tools/tiff2rgba.c b/tools/tiff2rgba.c index e0dbcc45..e1495f14 100644 --- a/tools/tiff2rgba.c +++ b/tools/tiff2rgba.c @@ -411,7 +411,7 @@ cvt_whole_image( TIFF *in, TIFF *out ) } if (maxMalloc != 0 && (tmsize_t)pixel_count * (tmsize_t)sizeof(uint32_t) > maxMalloc) { TIFFError(TIFFFileName(in), - "Raster size %zu over memory limit (%" TIFF_SSIZE_FORMAT "), try -b option.", + "Raster size %"TIFF_SIZE_FORMAT" over memory limit (%" TIFF_SSIZE_FORMAT "), try -b option.", pixel_count * sizeof(uint32_t), maxMalloc); return 0; } @@ -421,7 +421,7 @@ cvt_whole_image( TIFF *in, TIFF *out ) raster = (uint32_t*)_TIFFCheckMalloc(in, pixel_count, sizeof(uint32_t), "raster buffer"); if (raster == 0) { - TIFFError(TIFFFileName(in), "Failed to allocate buffer (%zu elements of %zu each)", + TIFFError(TIFFFileName(in), "Failed to allocate buffer (%"TIFF_SIZE_FORMAT" elements of %"TIFF_SIZE_FORMAT" each)", pixel_count, sizeof(uint32_t)); return (0); } -- cgit v1.2.1