From 63c666344fe6b8e28e27f69b5b0fd156ded40b14 Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Sun, 8 Mar 2020 00:51:28 +0100 Subject: [PATCH] Make pointers returned via TIFFGetField const According to http://bugzilla.maptools.org/show_bug.cgi?id=2125#c6 callers are not allowed to modify pointer or array values returned from TIFFGetField or the like. So, make this explicit in the documentation by specifying these things as const. Note that this is not an ABI change, since C does not encode const in libraries. Also, this is not really an API change, since the varargs call strips away all the types anyway. So it really is more of a documentation change. fixes #11 --- libtiff/tif_aux.c | 15 +++++------ libtiff/tif_dir.c | 30 ++++++++++----------- libtiff/tif_jpeg.c | 2 +- libtiff/tif_ojpeg.c | 6 ++--- man/TIFFGetField.3tiff | 60 +++++++++++++++++++++--------------------- 5 files changed, 56 insertions(+), 57 deletions(-) diff --git a/libtiff/tif_aux.c b/libtiff/tif_aux.c index 8188db53..bfe9d5ae 100644 --- a/libtiff/tif_aux.c +++ b/libtiff/tif_aux.c @@ -270,7 +270,7 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap) return (1); case TIFFTAG_EXTRASAMPLES: *va_arg(ap, uint16 *) = td->td_extrasamples; - *va_arg(ap, uint16 **) = td->td_sampleinfo; + *va_arg(ap, const uint16 **) = td->td_sampleinfo; return (1); case TIFFTAG_MATTEING: *va_arg(ap, uint16 *) = @@ -293,7 +293,7 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap) { /* defaults are from CCIR Recommendation 601-1 */ static float ycbcrcoeffs[] = { 0.299f, 0.587f, 0.114f }; - *va_arg(ap, float **) = ycbcrcoeffs; + *va_arg(ap, const float **) = ycbcrcoeffs; return 1; } case TIFFTAG_YCBCRSUBSAMPLING: @@ -306,13 +306,12 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap) case TIFFTAG_WHITEPOINT: { static float whitepoint[2]; - /* TIFF 6.0 specification tells that it is no default value for the WhitePoint, but AdobePhotoshop TIFF Technical Note tells that it should be CIE D50. */ whitepoint[0] = D50_X0 / (D50_X0 + D50_Y0 + D50_Z0); whitepoint[1] = D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0); - *va_arg(ap, float **) = whitepoint; + *va_arg(ap, const float **) = whitepoint; return 1; } case TIFFTAG_TRANSFERFUNCTION: @@ -321,16 +320,16 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap) TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "No space for \"TransferFunction\" tag"); return (0); } - *va_arg(ap, uint16 **) = td->td_transferfunction[0]; + *va_arg(ap, const uint16 **) = td->td_transferfunction[0]; if (td->td_samplesperpixel - td->td_extrasamples > 1) { - *va_arg(ap, uint16 **) = td->td_transferfunction[1]; - *va_arg(ap, uint16 **) = td->td_transferfunction[2]; + *va_arg(ap, const uint16 **) = td->td_transferfunction[1]; + *va_arg(ap, const uint16 **) = td->td_transferfunction[2]; } return (1); case TIFFTAG_REFERENCEBLACKWHITE: if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td)) return (0); - *va_arg(ap, float **) = td->td_refblackwhite; + *va_arg(ap, const float **) = td->td_refblackwhite; return (1); } return 0; diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c index 998b69aa..d72414b4 100644 --- a/libtiff/tif_dir.c +++ b/libtiff/tif_dir.c @@ -1033,19 +1033,19 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) *va_arg(ap, uint16*) = td->td_halftonehints[1]; break; case TIFFTAG_COLORMAP: - *va_arg(ap, uint16**) = td->td_colormap[0]; - *va_arg(ap, uint16**) = td->td_colormap[1]; - *va_arg(ap, uint16**) = td->td_colormap[2]; + *va_arg(ap, const uint16**) = td->td_colormap[0]; + *va_arg(ap, const uint16**) = td->td_colormap[1]; + *va_arg(ap, const uint16**) = td->td_colormap[2]; break; case TIFFTAG_STRIPOFFSETS: case TIFFTAG_TILEOFFSETS: _TIFFFillStriles( tif ); - *va_arg(ap, uint64**) = td->td_stripoffset_p; + *va_arg(ap, const uint64**) = td->td_stripoffset_p; break; case TIFFTAG_STRIPBYTECOUNTS: case TIFFTAG_TILEBYTECOUNTS: _TIFFFillStriles( tif ); - *va_arg(ap, uint64**) = td->td_stripbytecount_p; + *va_arg(ap, const uint64**) = td->td_stripbytecount_p; break; case TIFFTAG_MATTEING: *va_arg(ap, uint16*) = @@ -1054,7 +1054,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) break; case TIFFTAG_EXTRASAMPLES: *va_arg(ap, uint16*) = td->td_extrasamples; - *va_arg(ap, uint16**) = td->td_sampleinfo; + *va_arg(ap, const uint16**) = td->td_sampleinfo; break; case TIFFTAG_TILEWIDTH: *va_arg(ap, uint32*) = td->td_tilewidth; @@ -1089,7 +1089,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) break; case TIFFTAG_SUBIFD: *va_arg(ap, uint16*) = td->td_nsubifd; - *va_arg(ap, uint64**) = td->td_subifd; + *va_arg(ap, const uint64**) = td->td_subifd; break; case TIFFTAG_YCBCRPOSITIONING: *va_arg(ap, uint16*) = td->td_ycbcrpositioning; @@ -1099,20 +1099,20 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1]; break; case TIFFTAG_TRANSFERFUNCTION: - *va_arg(ap, uint16**) = td->td_transferfunction[0]; + *va_arg(ap, const uint16**) = td->td_transferfunction[0]; if (td->td_samplesperpixel - td->td_extrasamples > 1) { - *va_arg(ap, uint16**) = td->td_transferfunction[1]; - *va_arg(ap, uint16**) = td->td_transferfunction[2]; + *va_arg(ap, const uint16**) = td->td_transferfunction[1]; + *va_arg(ap, const uint16**) = td->td_transferfunction[2]; } else { - *va_arg(ap, uint16**) = NULL; - *va_arg(ap, uint16**) = NULL; + *va_arg(ap, const uint16**) = NULL; + *va_arg(ap, const uint16**) = NULL; } break; case TIFFTAG_REFERENCEBLACKWHITE: - *va_arg(ap, float**) = td->td_refblackwhite; + *va_arg(ap, const float**) = td->td_refblackwhite; break; case TIFFTAG_INKNAMES: - *va_arg(ap, char**) = td->td_inknames; + *va_arg(ap, const char**) = td->td_inknames; break; default: { @@ -1154,7 +1154,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) *va_arg(ap, uint32*) = (uint32)tv->count; else /* Assume TIFF_VARIABLE */ *va_arg(ap, uint16*) = (uint16)tv->count; - *va_arg(ap, void **) = tv->value; + *va_arg(ap, const void **) = tv->value; ret_val = 1; } else if (fip->field_tag == TIFFTAG_DOTRANGE && strcmp(fip->field_name,"DotRange") == 0) { diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c index 93ae2ead..489e849e 100644 --- a/libtiff/tif_jpeg.c +++ b/libtiff/tif_jpeg.c @@ -2344,7 +2344,7 @@ JPEGVGetField(TIFF* tif, uint32 tag, va_list ap) switch (tag) { case TIFFTAG_JPEGTABLES: *va_arg(ap, uint32*) = sp->jpegtables_length; - *va_arg(ap, void**) = sp->jpegtables; + *va_arg(ap, const void**) = sp->jpegtables; break; case TIFFTAG_JPEGQUALITY: *va_arg(ap, int*) = sp->jpegquality; diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c index aa5ff5e2..e2c9c4f9 100644 --- a/libtiff/tif_ojpeg.c +++ b/libtiff/tif_ojpeg.c @@ -498,15 +498,15 @@ OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap) break; case TIFFTAG_JPEGQTABLES: *va_arg(ap,uint32*)=(uint32)sp->qtable_offset_count; - *va_arg(ap,void**)=(void*)sp->qtable_offset; + *va_arg(ap,const void**)=(const void*)sp->qtable_offset; break; case TIFFTAG_JPEGDCTABLES: *va_arg(ap,uint32*)=(uint32)sp->dctable_offset_count; - *va_arg(ap,void**)=(void*)sp->dctable_offset; + *va_arg(ap,const void**)=(const void*)sp->dctable_offset; break; case TIFFTAG_JPEGACTABLES: *va_arg(ap,uint32*)=(uint32)sp->actable_offset_count; - *va_arg(ap,void**)=(void*)sp->actable_offset; + *va_arg(ap,const void**)=(const void*)sp->actable_offset; break; case TIFFTAG_JPEGPROC: *va_arg(ap,uint16*)=(uint16)sp->jpeg_proc; diff --git a/man/TIFFGetField.3tiff b/man/TIFFGetField.3tiff index c2fd025f..40f0323d 100644 --- a/man/TIFFGetField.3tiff +++ b/man/TIFFGetField.3tiff @@ -102,77 +102,77 @@ meaning of each tag and their possible values. .ta \w'TIFFTAG_CONSECUTIVEBADFAXLINES'u+2n +\w'Count'u+2n +\w'TIFFFaxFillFunc*'u+2n \fITag Name\fP \fICount\fP \fITypes\fP \fINotes\fP .sp 5p -TIFFTAG_ARTIST 1 char** +TIFFTAG_ARTIST 1 const char** TIFFTAG_BADFAXLINES 1 uint32* TIFFTAG_BITSPERSAMPLE 1 uint16* TIFFTAG_CLEANFAXDATA 1 uint16* -TIFFTAG_COLORMAP 3 uint16** 1<