libtiff/tif_dir.c:283: error: Memory Leak
  memory dynamically allocated by call to `_TIFFsetShortArray()` at line 282, column 3 is not reachable after line 283, column 3.

libtiff/tif_dir.c:138:1: start of procedure _TIFFVSetField()
136. }
137. 
138. static int
     ^
139. _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
140. {

libtiff/tif_dir.c:141:2: 
139. _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
140. {
141. 	static const char module[] = "_TIFFVSetField";
      ^
142. 
143. 	TIFFDirectory* td = &tif->tif_dir;

libtiff/tif_dir.c:143:2: 
141. 	static const char module[] = "_TIFFVSetField";
142. 
143. 	TIFFDirectory* td = &tif->tif_dir;
      ^
144. 	int status = 1;
145. 	uint32 v32, i, v;

libtiff/tif_dir.c:144:2: 
142. 
143. 	TIFFDirectory* td = &tif->tif_dir;
144. 	int status = 1;
      ^
145. 	uint32 v32, i, v;
146. 	char* s;

libtiff/tif_dir.c:148:2: 
146. 	char* s;
147. 
148. 	switch (tag) {
      ^
149. 	case TIFFTAG_SUBFILETYPE:
150. 		td->td_subfiletype = (uint32) va_arg(ap, uint32);

libtiff/tif_dir.c:149:2: Switch condition is false. Skipping switch case
147. 
148. 	switch (tag) {
149. 	case TIFFTAG_SUBFILETYPE:
      ^
150. 		td->td_subfiletype = (uint32) va_arg(ap, uint32);
151. 		break;

libtiff/tif_dir.c:152:2: Switch condition is false. Skipping switch case
150. 		td->td_subfiletype = (uint32) va_arg(ap, uint32);
151. 		break;
152. 	case TIFFTAG_IMAGEWIDTH:
      ^
153. 		td->td_imagewidth = (uint32) va_arg(ap, uint32);
154. 		break;

libtiff/tif_dir.c:155:2: Switch condition is false. Skipping switch case
153. 		td->td_imagewidth = (uint32) va_arg(ap, uint32);
154. 		break;
155. 	case TIFFTAG_IMAGELENGTH:
      ^
156. 		td->td_imagelength = (uint32) va_arg(ap, uint32);
157. 		break;

libtiff/tif_dir.c:158:2: Switch condition is false. Skipping switch case
156. 		td->td_imagelength = (uint32) va_arg(ap, uint32);
157. 		break;
158. 	case TIFFTAG_BITSPERSAMPLE:
      ^
159. 		td->td_bitspersample = (uint16) va_arg(ap, uint16_vap);
160. 		/*

libtiff/tif_dir.c:180:2: Switch condition is false. Skipping switch case
178. 		}
179. 		break;
180. 	case TIFFTAG_COMPRESSION:
      ^
181. 		v = (uint16) va_arg(ap, uint16_vap);
182. 		/*

libtiff/tif_dir.c:201:2: Switch condition is false. Skipping switch case
199. 		    status = 0;
200. 		break;
201. 	case TIFFTAG_PHOTOMETRIC:
      ^
202. 		td->td_photometric = (uint16) va_arg(ap, uint16_vap);
203. 		break;

libtiff/tif_dir.c:204:2: Switch condition is false. Skipping switch case
202. 		td->td_photometric = (uint16) va_arg(ap, uint16_vap);
203. 		break;
204. 	case TIFFTAG_THRESHHOLDING:
      ^
205. 		td->td_threshholding = (uint16) va_arg(ap, uint16_vap);
206. 		break;

libtiff/tif_dir.c:207:2: Switch condition is false. Skipping switch case
205. 		td->td_threshholding = (uint16) va_arg(ap, uint16_vap);
206. 		break;
207. 	case TIFFTAG_FILLORDER:
      ^
208. 		v = (uint16) va_arg(ap, uint16_vap);
209. 		if (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB)

libtiff/tif_dir.c:213:2: Switch condition is false. Skipping switch case
211. 		td->td_fillorder = (uint16) v;
212. 		break;
213. 	case TIFFTAG_ORIENTATION:
      ^
214. 		v = (uint16) va_arg(ap, uint16_vap);
215. 		if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v)

libtiff/tif_dir.c:220:2: Switch condition is false. Skipping switch case
218. 			td->td_orientation = (uint16) v;
219. 		break;
220. 	case TIFFTAG_SAMPLESPERPIXEL:
      ^
221. 		v = (uint16) va_arg(ap, uint16_vap);
222. 		if (v == 0)

libtiff/tif_dir.c:226:2: Switch condition is false. Skipping switch case
224. 		td->td_samplesperpixel = (uint16) v;
225. 		break;
226. 	case TIFFTAG_ROWSPERSTRIP:
      ^
227. 		v32 = (uint32) va_arg(ap, uint32);
228. 		if (v32 == 0)

libtiff/tif_dir.c:236:2: Switch condition is false. Skipping switch case
234. 		}
235. 		break;
236. 	case TIFFTAG_MINSAMPLEVALUE:
      ^
237. 		td->td_minsamplevalue = (uint16) va_arg(ap, uint16_vap);
238. 		break;

libtiff/tif_dir.c:239:2: Switch condition is false. Skipping switch case
237. 		td->td_minsamplevalue = (uint16) va_arg(ap, uint16_vap);
238. 		break;
239. 	case TIFFTAG_MAXSAMPLEVALUE:
      ^
240. 		td->td_maxsamplevalue = (uint16) va_arg(ap, uint16_vap);
241. 		break;

libtiff/tif_dir.c:242:2: Switch condition is false. Skipping switch case
240. 		td->td_maxsamplevalue = (uint16) va_arg(ap, uint16_vap);
241. 		break;
242. 	case TIFFTAG_SMINSAMPLEVALUE:
      ^
243. 		td->td_sminsamplevalue = (double) va_arg(ap, double);
244. 		break;

libtiff/tif_dir.c:245:2: Switch condition is false. Skipping switch case
243. 		td->td_sminsamplevalue = (double) va_arg(ap, double);
244. 		break;
245. 	case TIFFTAG_SMAXSAMPLEVALUE:
      ^
246. 		td->td_smaxsamplevalue = (double) va_arg(ap, double);
247. 		break;

libtiff/tif_dir.c:248:2: Switch condition is false. Skipping switch case
246. 		td->td_smaxsamplevalue = (double) va_arg(ap, double);
247. 		break;
248. 	case TIFFTAG_XRESOLUTION:
      ^
249. 		td->td_xresolution = (float) va_arg(ap, double);
250. 		break;

libtiff/tif_dir.c:251:2: Switch condition is false. Skipping switch case
249. 		td->td_xresolution = (float) va_arg(ap, double);
250. 		break;
251. 	case TIFFTAG_YRESOLUTION:
      ^
252. 		td->td_yresolution = (float) va_arg(ap, double);
253. 		break;

libtiff/tif_dir.c:254:2: Switch condition is false. Skipping switch case
252. 		td->td_yresolution = (float) va_arg(ap, double);
253. 		break;
254. 	case TIFFTAG_PLANARCONFIG:
      ^
255. 		v = (uint16) va_arg(ap, uint16_vap);
256. 		if (v != PLANARCONFIG_CONTIG && v != PLANARCONFIG_SEPARATE)

libtiff/tif_dir.c:260:2: Switch condition is false. Skipping switch case
258. 		td->td_planarconfig = (uint16) v;
259. 		break;
260. 	case TIFFTAG_XPOSITION:
      ^
261. 		td->td_xposition = (float) va_arg(ap, double);
262. 		break;

libtiff/tif_dir.c:263:2: Switch condition is false. Skipping switch case
261. 		td->td_xposition = (float) va_arg(ap, double);
262. 		break;
263. 	case TIFFTAG_YPOSITION:
      ^
264. 		td->td_yposition = (float) va_arg(ap, double);
265. 		break;

libtiff/tif_dir.c:266:2: Switch condition is false. Skipping switch case
264. 		td->td_yposition = (float) va_arg(ap, double);
265. 		break;
266. 	case TIFFTAG_RESOLUTIONUNIT:
      ^
267. 		v = (uint16) va_arg(ap, uint16_vap);
268. 		if (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v)

libtiff/tif_dir.c:272:2: Switch condition is false. Skipping switch case
270. 		td->td_resolutionunit = (uint16) v;
271. 		break;
272. 	case TIFFTAG_PAGENUMBER:
      ^
273. 		td->td_pagenumber[0] = (uint16) va_arg(ap, uint16_vap);
274. 		td->td_pagenumber[1] = (uint16) va_arg(ap, uint16_vap);

libtiff/tif_dir.c:276:2: Switch condition is false. Skipping switch case
274. 		td->td_pagenumber[1] = (uint16) va_arg(ap, uint16_vap);
275. 		break;
276. 	case TIFFTAG_HALFTONEHINTS:
      ^
277. 		td->td_halftonehints[0] = (uint16) va_arg(ap, uint16_vap);
278. 		td->td_halftonehints[1] = (uint16) va_arg(ap, uint16_vap);

libtiff/tif_dir.c:280:2: Switch condition is true. Entering switch case
278. 		td->td_halftonehints[1] = (uint16) va_arg(ap, uint16_vap);
279. 		break;
280. 	case TIFFTAG_COLORMAP:
      ^
281. 		v32 = (uint32)(1L<<td->td_bitspersample);
282. 		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);

libtiff/tif_dir.c:281:3: 
279. 		break;
280. 	case TIFFTAG_COLORMAP:
281. 		v32 = (uint32)(1L<<td->td_bitspersample);
       ^
282. 		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
283. 		_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);

libtiff/tif_dir.c:282:3: 
280. 	case TIFFTAG_COLORMAP:
281. 		v32 = (uint32)(1L<<td->td_bitspersample);
282. 		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
       ^
283. 		_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);
284. 		_TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);

libtiff/tif_dir.c:62:1: start of procedure _TIFFsetShortArray()
  60. void _TIFFsetNString(char** cpp, char* cp, uint32 n)
  61.     { setByteArray((void**) cpp, (void*) cp, n, 1); }
  62. void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
      ^
  63.     { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
  64. void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)

libtiff/tif_dir.c:63:7: 
  61.     { setByteArray((void**) cpp, (void*) cp, n, 1); }
  62. void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
  63.     { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
            ^
  64. void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)
  65.     { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }

libtiff/tif_dir.c:43:1: start of procedure setByteArray()
    41. #define DATATYPE_IEEEFP		3       /* !IEEE floating point data */
    42. 
    43. static void
        ^
    44. setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
    45. {

libtiff/tif_dir.c:46:6: Taking true branch
    44. setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
    45. {
    46. 	if (*vpp)
             ^
    47. 		_TIFFfree(*vpp), *vpp = 0;
    48. 	if (vp) {

libtiff/tif_dir.c:47:3: 
    45. {
    46. 	if (*vpp)
    47. 		_TIFFfree(*vpp), *vpp = 0;
          ^
    48. 	if (vp) {
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);

libtiff/tif_unix.c:259:1: start of procedure _TIFFfree()
      257. }
      258. 
      259. void
           ^
      260. _TIFFfree(void* p)
      261. {

libtiff/tif_unix.c:262:2: 
      260. _TIFFfree(void* p)
      261. {
      262. 	free(p);
            ^
      263. }
      264. 

libtiff/tif_unix.c:263:1: return from a call to _TIFFfree
      261. {
      262. 	free(p);
      263. }
           ^
      264. 
      265. void*

libtiff/tif_dir.c:48:6: Taking true branch
    46. 	if (*vpp)
    47. 		_TIFFfree(*vpp), *vpp = 0;
    48. 	if (vp) {
             ^
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
    50. 		if (elem_size && bytes / elem_size == nmemb)

libtiff/tif_dir.c:49:3: 
    47. 		_TIFFfree(*vpp), *vpp = 0;
    48. 	if (vp) {
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
          ^
    50. 		if (elem_size && bytes / elem_size == nmemb)
    51. 			*vpp = (void*) _TIFFmalloc(bytes);

libtiff/tif_dir.c:50:7: Taking true branch
    48. 	if (vp) {
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
    50. 		if (elem_size && bytes / elem_size == nmemb)
              ^
    51. 			*vpp = (void*) _TIFFmalloc(bytes);
    52. 		if (*vpp)

libtiff/tif_dir.c:50:20: Taking true branch
    48. 	if (vp) {
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
    50. 		if (elem_size && bytes / elem_size == nmemb)
                           ^
    51. 			*vpp = (void*) _TIFFmalloc(bytes);
    52. 		if (*vpp)

libtiff/tif_dir.c:51:4: 
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
    50. 		if (elem_size && bytes / elem_size == nmemb)
    51. 			*vpp = (void*) _TIFFmalloc(bytes);
           ^
    52. 		if (*vpp)
    53. 			_TIFFmemcpy(*vpp, vp, bytes);

libtiff/tif_unix.c:253:1: start of procedure _TIFFmalloc()
      251. #endif
      252. 
      253. void*
           ^
      254. _TIFFmalloc(tmsize_t s)
      255. {

libtiff/tif_unix.c:256:2: 
      254. _TIFFmalloc(tmsize_t s)
      255. {
      256. 	return (malloc((size_t) s));
            ^
      257. }
      258. 

libtiff/tif_unix.c:257:1: return from a call to _TIFFmalloc
      255. {
      256. 	return (malloc((size_t) s));
      257. }
           ^
      258. 
      259. void

libtiff/tif_dir.c:52:7: Taking true branch
    50. 		if (elem_size && bytes / elem_size == nmemb)
    51. 			*vpp = (void*) _TIFFmalloc(bytes);
    52. 		if (*vpp)
              ^
    53. 			_TIFFmemcpy(*vpp, vp, bytes);
    54. 	}

libtiff/tif_dir.c:53:4: 
    51. 			*vpp = (void*) _TIFFmalloc(bytes);
    52. 		if (*vpp)
    53. 			_TIFFmemcpy(*vpp, vp, bytes);
           ^
    54. 	}
    55. }

libtiff/tif_unix.c:277:1: start of procedure _TIFFmemcpy()
      275. }
      276. 
      277. void
           ^
      278. _TIFFmemcpy(void* d, const void* s, tmsize_t c)
      279. {

libtiff/tif_unix.c:280:2: 
      278. _TIFFmemcpy(void* d, const void* s, tmsize_t c)
      279. {
      280. 	memcpy(d, s, (size_t) c);
            ^
      281. }
      282. 

libtiff/tif_unix.c:281:1: return from a call to _TIFFmemcpy
      279. {
      280. 	memcpy(d, s, (size_t) c);
      281. }
           ^
      282. 
      283. int

libtiff/tif_dir.c:48:2: 
    46. 	if (*vpp)
    47. 		_TIFFfree(*vpp), *vpp = 0;
    48. 	if (vp) {
         ^
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
    50. 		if (elem_size && bytes / elem_size == nmemb)

libtiff/tif_dir.c:55:1: return from a call to setByteArray
    53. 			_TIFFmemcpy(*vpp, vp, bytes);
    54. 	}
    55. }
        ^
    56. void _TIFFsetByteArray(void** vpp, void* vp, uint32 n)
    57.     { setByteArray(vpp, vp, n, 1); }

libtiff/tif_dir.c:63:67: return from a call to _TIFFsetShortArray
  61.     { setByteArray((void**) cpp, (void*) cp, n, 1); }
  62. void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
  63.     { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
                                                                        ^
  64. void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)
  65.     { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }

libtiff/tif_dir.c:283:3: 
281. 		v32 = (uint32)(1L<<td->td_bitspersample);
282. 		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
283. 		_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);
       ^
284. 		_TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);
285. 		break;

libtiff/tif_dir.c:62:1: start of procedure _TIFFsetShortArray()
  60. void _TIFFsetNString(char** cpp, char* cp, uint32 n)
  61.     { setByteArray((void**) cpp, (void*) cp, n, 1); }
  62. void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
      ^
  63.     { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
  64. void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)

libtiff/tif_dir.c:63:7: 
  61.     { setByteArray((void**) cpp, (void*) cp, n, 1); }
  62. void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
  63.     { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
            ^
  64. void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)
  65.     { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }

libtiff/tif_dir.c:43:1: start of procedure setByteArray()
    41. #define DATATYPE_IEEEFP		3       /* !IEEE floating point data */
    42. 
    43. static void
        ^
    44. setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
    45. {

libtiff/tif_dir.c:46:6: Taking false branch
    44. setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
    45. {
    46. 	if (*vpp)
             ^
    47. 		_TIFFfree(*vpp), *vpp = 0;
    48. 	if (vp) {

libtiff/tif_dir.c:48:6: Taking false branch
    46. 	if (*vpp)
    47. 		_TIFFfree(*vpp), *vpp = 0;
    48. 	if (vp) {
             ^
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
    50. 		if (elem_size && bytes / elem_size == nmemb)

libtiff/tif_dir.c:48:2: 
    46. 	if (*vpp)
    47. 		_TIFFfree(*vpp), *vpp = 0;
    48. 	if (vp) {
         ^
    49. 		tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
    50. 		if (elem_size && bytes / elem_size == nmemb)

libtiff/tif_dir.c:55:1: return from a call to setByteArray
    53. 			_TIFFmemcpy(*vpp, vp, bytes);
    54. 	}
    55. }
        ^
    56. void _TIFFsetByteArray(void** vpp, void* vp, uint32 n)
    57.     { setByteArray(vpp, vp, n, 1); }

libtiff/tif_dir.c:63:67: return from a call to _TIFFsetShortArray
  61.     { setByteArray((void**) cpp, (void*) cp, n, 1); }
  62. void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
  63.     { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
                                                                        ^
  64. void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)
  65.     { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }

static int
_TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
{
	static const char module[] = "_TIFFVSetField";
	TIFFDirectory* td = &tif->tif_dir;
	int status = 1;
	uint32 v32, i, v;
	char* s;
	switch (tag) {
	case TIFFTAG_SUBFILETYPE:
		td->td_subfiletype = (uint32) va_arg(ap, uint32);
		break;
	case TIFFTAG_IMAGEWIDTH:
		td->td_imagewidth = (uint32) va_arg(ap, uint32);
		break;
	case TIFFTAG_IMAGELENGTH:
		td->td_imagelength = (uint32) va_arg(ap, uint32);
		break;
	case TIFFTAG_BITSPERSAMPLE:
		td->td_bitspersample = (uint16) va_arg(ap, uint16_vap);
		if (tif->tif_flags & TIFF_SWAB) {
			if (td->td_bitspersample == 16)
				tif->tif_postdecode = _TIFFSwab16BitData;
			else if (td->td_bitspersample == 24)
				tif->tif_postdecode = _TIFFSwab24BitData;
			else if (td->td_bitspersample == 32)
				tif->tif_postdecode = _TIFFSwab32BitData;
			else if (td->td_bitspersample == 64)
				tif->tif_postdecode = _TIFFSwab64BitData;
			else if (td->td_bitspersample == 128)
				tif->tif_postdecode = _TIFFSwab64BitData;
		}
		break;
	case TIFFTAG_COMPRESSION:
		v = (uint16) va_arg(ap, uint16_vap);
		if (TIFFFieldSet(tif, FIELD_COMPRESSION)) {
			if ((uint32)td->td_compression == v)
				break;
			(*tif->tif_cleanup)(tif);
			tif->tif_flags &= ~TIFF_CODERSETUP;
		}
		if( (status = TIFFSetCompressionScheme(tif, v)) != 0 )
		    td->td_compression = (uint16) v;
		else
		    status = 0;
		break;
	case TIFFTAG_PHOTOMETRIC:
		td->td_photometric = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_THRESHHOLDING:
		td->td_threshholding = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_FILLORDER:
		v = (uint16) va_arg(ap, uint16_vap);
		if (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB)
			goto badvalue;
		td->td_fillorder = (uint16) v;
		break;
	case TIFFTAG_ORIENTATION:
		v = (uint16) va_arg(ap, uint16_vap);
		if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v)
			goto badvalue;
		else
			td->td_orientation = (uint16) v;
		break;
	case TIFFTAG_SAMPLESPERPIXEL:
		v = (uint16) va_arg(ap, uint16_vap);
		if (v == 0)
			goto badvalue;
		td->td_samplesperpixel = (uint16) v;
		break;
	case TIFFTAG_ROWSPERSTRIP:
		v32 = (uint32) va_arg(ap, uint32);
		if (v32 == 0)
			goto badvalue32;
		td->td_rowsperstrip = v32;
		if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {
			td->td_tilelength = v32;
			td->td_tilewidth = td->td_imagewidth;
		}
		break;
	case TIFFTAG_MINSAMPLEVALUE:
		td->td_minsamplevalue = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_MAXSAMPLEVALUE:
		td->td_maxsamplevalue = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_SMINSAMPLEVALUE:
		td->td_sminsamplevalue = (double) va_arg(ap, double);
		break;
	case TIFFTAG_SMAXSAMPLEVALUE:
		td->td_smaxsamplevalue = (double) va_arg(ap, double);
		break;
	case TIFFTAG_XRESOLUTION:
		td->td_xresolution = (float) va_arg(ap, double);
		break;
	case TIFFTAG_YRESOLUTION:
		td->td_yresolution = (float) va_arg(ap, double);
		break;
	case TIFFTAG_PLANARCONFIG:
		v = (uint16) va_arg(ap, uint16_vap);
		if (v != PLANARCONFIG_CONTIG && v != PLANARCONFIG_SEPARATE)
			goto badvalue;
		td->td_planarconfig = (uint16) v;
		break;
	case TIFFTAG_XPOSITION:
		td->td_xposition = (float) va_arg(ap, double);
		break;
	case TIFFTAG_YPOSITION:
		td->td_yposition = (float) va_arg(ap, double);
		break;
	case TIFFTAG_RESOLUTIONUNIT:
		v = (uint16) va_arg(ap, uint16_vap);
		if (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v)
			goto badvalue;
		td->td_resolutionunit = (uint16) v;
		break;
	case TIFFTAG_PAGENUMBER:
		td->td_pagenumber[0] = (uint16) va_arg(ap, uint16_vap);
		td->td_pagenumber[1] = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_HALFTONEHINTS:
		td->td_halftonehints[0] = (uint16) va_arg(ap, uint16_vap);
		td->td_halftonehints[1] = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_COLORMAP:
		v32 = (uint32)(1L<<td->td_bitspersample);
		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
		_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);
		_TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);
		break;
	case TIFFTAG_EXTRASAMPLES:
		if (!setExtraSamples(td, ap, &v))
			goto badvalue;
		break;
	case TIFFTAG_MATTEING:
		td->td_extrasamples =  (((uint16) va_arg(ap, uint16_vap)) != 0);
		if (td->td_extrasamples) {
			uint16 sv = EXTRASAMPLE_ASSOCALPHA;
			_TIFFsetShortArray(&td->td_sampleinfo, &sv, 1);
		}
		break;
	case TIFFTAG_TILEWIDTH:
		v32 = (uint32) va_arg(ap, uint32);
		if (v32 % 16) {
			if (tif->tif_mode != O_RDONLY)
				goto badvalue32;
			TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
				"Nonstandard tile width %d, convert file", v32);
		}
		td->td_tilewidth = v32;
		tif->tif_flags |= TIFF_ISTILED;
		break;
	case TIFFTAG_TILELENGTH:
		v32 = (uint32) va_arg(ap, uint32);
		if (v32 % 16) {
			if (tif->tif_mode != O_RDONLY)
				goto badvalue32;
			TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
			    "Nonstandard tile length %d, convert file", v32);
		}
		td->td_tilelength = v32;
		tif->tif_flags |= TIFF_ISTILED;
		break;
	case TIFFTAG_TILEDEPTH:
		v32 = (uint32) va_arg(ap, uint32);
		if (v32 == 0)
			goto badvalue32;
		td->td_tiledepth = v32;
		break;
	case TIFFTAG_DATATYPE:
		v = (uint16) va_arg(ap, uint16_vap);
		switch (v) {
		case DATATYPE_VOID:	v = SAMPLEFORMAT_VOID;	break;
		case DATATYPE_INT:	v = SAMPLEFORMAT_INT;	break;
		case DATATYPE_UINT:	v = SAMPLEFORMAT_UINT;	break;
		case DATATYPE_IEEEFP:	v = SAMPLEFORMAT_IEEEFP;break;
		default:		goto badvalue;
		}
		td->td_sampleformat = (uint16) v;
		break;
	case TIFFTAG_SAMPLEFORMAT:
		v = (uint16) va_arg(ap, uint16_vap);
		if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v)
			goto badvalue;
		td->td_sampleformat = (uint16) v;
		if( td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT
		    && td->td_bitspersample == 32
		    && tif->tif_postdecode == _TIFFSwab32BitData )
		    tif->tif_postdecode = _TIFFSwab16BitData;
		else if( (td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT
			  || td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP)
			 && td->td_bitspersample == 64
			 && tif->tif_postdecode == _TIFFSwab64BitData )
		    tif->tif_postdecode = _TIFFSwab32BitData;
		break;
	case TIFFTAG_IMAGEDEPTH:
		td->td_imagedepth = (uint32) va_arg(ap, uint32);
		break;
	case TIFFTAG_SUBIFD:
		if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
			td->td_nsubifd = (uint16) va_arg(ap, uint16_vap);
			_TIFFsetLong8Array(&td->td_subifd, (uint64*) va_arg(ap, uint64*),
			    (long) td->td_nsubifd);
		} else {
			TIFFErrorExt(tif->tif_clientdata, module,
				     "%s: Sorry, cannot nest SubIFDs",
				     tif->tif_name);
			status = 0;
		}
		break;
	case TIFFTAG_YCBCRPOSITIONING:
		td->td_ycbcrpositioning = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_YCBCRSUBSAMPLING:
		td->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, uint16_vap);
		td->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, uint16_vap);
		break;
	case TIFFTAG_TRANSFERFUNCTION:
		v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1;
		for (i = 0; i < v; i++)
			_TIFFsetShortArray(&td->td_transferfunction[i],
			    va_arg(ap, uint16*), 1L<<td->td_bitspersample);
		break;
	case TIFFTAG_INKNAMES:
		v = (uint16) va_arg(ap, uint16_vap);
		s = va_arg(ap, char*);
		v = checkInkNamesString(tif, v, s);
		status = v > 0;
		if( v > 0 ) {
			_TIFFsetNString(&td->td_inknames, s, v);
			td->td_inknameslen = v;
		}
		break;
	default: {
		TIFFTagValue *tv;
		int tv_size, iCustom;
		const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
		if(fip == NULL || fip->field_bit != FIELD_CUSTOM) {
			TIFFErrorExt(tif->tif_clientdata, module,
			    "%s: Invalid %stag \"%s\" (not supported by codec)",
			    tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
			    fip ? fip->field_name : "Unknown");
			status = 0;
			break;
		}
		tv = NULL;
		for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) {
			if (td->td_customValues[iCustom].info->field_tag == tag) {
				tv = td->td_customValues + iCustom;
				if (tv->value != NULL) {
					_TIFFfree(tv->value);
					tv->value = NULL;
				}
				break;
			}
		}
		if(tv == NULL) {
			TIFFTagValue *new_customValues;
			td->td_customValueCount++;
			new_customValues = (TIFFTagValue *)
			    _TIFFrealloc(td->td_customValues,
			    sizeof(TIFFTagValue) * td->td_customValueCount);
			if (!new_customValues) {
				TIFFErrorExt(tif->tif_clientdata, module,
				    "%s: Failed to allocate space for list of custom values",
				    tif->tif_name);
				status = 0;
				goto end;
			}
			td->td_customValues = new_customValues;
			tv = td->td_customValues + (td->td_customValueCount - 1);
			tv->info = fip;
			tv->value = NULL;
			tv->count = 0;
		}
		tv_size = _TIFFDataSize(fip->field_type);
		if (tv_size == 0) {
			status = 0;
			TIFFErrorExt(tif->tif_clientdata, module,
			    "%s: Bad field type %d for \"%s\"",
			    tif->tif_name, fip->field_type,
			    fip->field_name);
			goto end;
		}
		if (fip->field_type == TIFF_ASCII)
		{
			uint32 ma;
			char* mb;
			if (fip->field_passcount)
			{
				assert(fip->field_writecount==TIFF_VARIABLE2);
				ma=(uint32)va_arg(ap,uint32);
				mb=(char*)va_arg(ap,char*);
			}
			else
			{
				mb=(char*)va_arg(ap,char*);
				ma=(uint32)(strlen(mb)+1);
			}
			tv->count=ma;
			setByteArray(&tv->value,mb,ma,1);
		}
		else
		{
			if(fip->field_passcount) {
				if (fip->field_writecount == TIFF_VARIABLE2)
					tv->count = (uint32) va_arg(ap, uint32);
				else
					tv->count = (int) va_arg(ap, int);
			} else if (fip->field_writecount == TIFF_VARIABLE
			   || fip->field_writecount == TIFF_VARIABLE2)
				tv->count = 1;
			else if (fip->field_writecount == TIFF_SPP)
				tv->count = td->td_samplesperpixel;
			else
				tv->count = fip->field_writecount;
			tv->value = _TIFFCheckMalloc(tif, tv_size, tv->count,
			    "Tag Value");
			if (!tv->value) {
				status = 0;
				goto end;
			}
			if ((fip->field_passcount
			    || fip->field_writecount == TIFF_VARIABLE
			    || fip->field_writecount == TIFF_VARIABLE2
			    || fip->field_writecount == TIFF_SPP
			    || tv->count > 1)
			    && fip->field_tag != TIFFTAG_PAGENUMBER
			    && fip->field_tag != TIFFTAG_HALFTONEHINTS
			    && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
			    && fip->field_tag != TIFFTAG_DOTRANGE) {
				_TIFFmemcpy(tv->value, va_arg(ap, void *),
				    tv->count * tv_size);
			} else {
				int i;
				char *val = (char *)tv->value;
				for (i = 0; i < tv->count; i++, val += tv_size) {
					switch (fip->field_type) {
						case TIFF_BYTE:
						case TIFF_UNDEFINED:
							{
								uint8 v = (uint8)va_arg(ap, int);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_SBYTE:
							{
								int8 v = (int8)va_arg(ap, int);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_SHORT:
							{
								uint16 v = (uint16)va_arg(ap, int);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_SSHORT:
							{
								int16 v = (int16)va_arg(ap, int);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_LONG:
						case TIFF_IFD:
							{
								uint32 v = va_arg(ap, uint32);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_SLONG:
							{
								int32 v = va_arg(ap, int32);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_LONG8:
						case TIFF_IFD8:
							{
								uint64 v = va_arg(ap, uint64);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_SLONG8:
							{
								int64 v = va_arg(ap, int64);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_RATIONAL:
						case TIFF_SRATIONAL:
						case TIFF_FLOAT:
							{
								float v = (float)va_arg(ap, double);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						case TIFF_DOUBLE:
							{
								double v = va_arg(ap, double);
								_TIFFmemcpy(val, &v, tv_size);
							}
							break;
						default:
							_TIFFmemset(val, 0, tv_size);
							status = 0;
							break;
					}
				}
			}
		}
	}
	}
	if (status) {
		TIFFSetFieldBit(tif, TIFFFieldWithTag(tif, tag)->field_bit);
		tif->tif_flags |= TIFF_DIRTYDIRECT;
	}
end:
	va_end(ap);
	return (status);
badvalue:
	TIFFErrorExt(tif->tif_clientdata, module,
		     "%s: Bad value %u for \"%s\" tag",
		     tif->tif_name, v,
		     TIFFFieldWithTag(tif, tag)->field_name);
	va_end(ap);
	return (0);
badvalue32:
	TIFFErrorExt(tif->tif_clientdata, module,
		     "%s: Bad value %u for \"%s\" tag",
		     tif->tif_name, v32,
		     TIFFFieldWithTag(tif, tag)->field_name);
	va_end(ap);
	return (0);
}
['static int\n_TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)\n{\n\tstatic const char module[] = "_TIFFVSetField";\n\tTIFFDirectory* td = &tif->tif_dir;\n\tint status = 1;\n\tuint32 v32, i, v;\n\tchar* s;\n\tswitch (tag) {\n\tcase TIFFTAG_SUBFILETYPE:\n\t\ttd->td_subfiletype = (uint32) va_arg(ap, uint32);\n\t\tbreak;\n\tcase TIFFTAG_IMAGEWIDTH:\n\t\ttd->td_imagewidth = (uint32) va_arg(ap, uint32);\n\t\tbreak;\n\tcase TIFFTAG_IMAGELENGTH:\n\t\ttd->td_imagelength = (uint32) va_arg(ap, uint32);\n\t\tbreak;\n\tcase TIFFTAG_BITSPERSAMPLE:\n\t\ttd->td_bitspersample = (uint16) va_arg(ap, uint16_vap);\n\t\tif (tif->tif_flags & TIFF_SWAB) {\n\t\t\tif (td->td_bitspersample == 16)\n\t\t\t\ttif->tif_postdecode = _TIFFSwab16BitData;\n\t\t\telse if (td->td_bitspersample == 24)\n\t\t\t\ttif->tif_postdecode = _TIFFSwab24BitData;\n\t\t\telse if (td->td_bitspersample == 32)\n\t\t\t\ttif->tif_postdecode = _TIFFSwab32BitData;\n\t\t\telse if (td->td_bitspersample == 64)\n\t\t\t\ttif->tif_postdecode = _TIFFSwab64BitData;\n\t\t\telse if (td->td_bitspersample == 128)\n\t\t\t\ttif->tif_postdecode = _TIFFSwab64BitData;\n\t\t}\n\t\tbreak;\n\tcase TIFFTAG_COMPRESSION:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tif (TIFFFieldSet(tif, FIELD_COMPRESSION)) {\n\t\t\tif ((uint32)td->td_compression == v)\n\t\t\t\tbreak;\n\t\t\t(*tif->tif_cleanup)(tif);\n\t\t\ttif->tif_flags &= ~TIFF_CODERSETUP;\n\t\t}\n\t\tif( (status = TIFFSetCompressionScheme(tif, v)) != 0 )\n\t\t    td->td_compression = (uint16) v;\n\t\telse\n\t\t    status = 0;\n\t\tbreak;\n\tcase TIFFTAG_PHOTOMETRIC:\n\t\ttd->td_photometric = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_THRESHHOLDING:\n\t\ttd->td_threshholding = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_FILLORDER:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tif (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB)\n\t\t\tgoto badvalue;\n\t\ttd->td_fillorder = (uint16) v;\n\t\tbreak;\n\tcase TIFFTAG_ORIENTATION:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tif (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v)\n\t\t\tgoto badvalue;\n\t\telse\n\t\t\ttd->td_orientation = (uint16) v;\n\t\tbreak;\n\tcase TIFFTAG_SAMPLESPERPIXEL:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tif (v == 0)\n\t\t\tgoto badvalue;\n\t\ttd->td_samplesperpixel = (uint16) v;\n\t\tbreak;\n\tcase TIFFTAG_ROWSPERSTRIP:\n\t\tv32 = (uint32) va_arg(ap, uint32);\n\t\tif (v32 == 0)\n\t\t\tgoto badvalue32;\n\t\ttd->td_rowsperstrip = v32;\n\t\tif (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {\n\t\t\ttd->td_tilelength = v32;\n\t\t\ttd->td_tilewidth = td->td_imagewidth;\n\t\t}\n\t\tbreak;\n\tcase TIFFTAG_MINSAMPLEVALUE:\n\t\ttd->td_minsamplevalue = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_MAXSAMPLEVALUE:\n\t\ttd->td_maxsamplevalue = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_SMINSAMPLEVALUE:\n\t\ttd->td_sminsamplevalue = (double) va_arg(ap, double);\n\t\tbreak;\n\tcase TIFFTAG_SMAXSAMPLEVALUE:\n\t\ttd->td_smaxsamplevalue = (double) va_arg(ap, double);\n\t\tbreak;\n\tcase TIFFTAG_XRESOLUTION:\n\t\ttd->td_xresolution = (float) va_arg(ap, double);\n\t\tbreak;\n\tcase TIFFTAG_YRESOLUTION:\n\t\ttd->td_yresolution = (float) va_arg(ap, double);\n\t\tbreak;\n\tcase TIFFTAG_PLANARCONFIG:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tif (v != PLANARCONFIG_CONTIG && v != PLANARCONFIG_SEPARATE)\n\t\t\tgoto badvalue;\n\t\ttd->td_planarconfig = (uint16) v;\n\t\tbreak;\n\tcase TIFFTAG_XPOSITION:\n\t\ttd->td_xposition = (float) va_arg(ap, double);\n\t\tbreak;\n\tcase TIFFTAG_YPOSITION:\n\t\ttd->td_yposition = (float) va_arg(ap, double);\n\t\tbreak;\n\tcase TIFFTAG_RESOLUTIONUNIT:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tif (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v)\n\t\t\tgoto badvalue;\n\t\ttd->td_resolutionunit = (uint16) v;\n\t\tbreak;\n\tcase TIFFTAG_PAGENUMBER:\n\t\ttd->td_pagenumber[0] = (uint16) va_arg(ap, uint16_vap);\n\t\ttd->td_pagenumber[1] = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_HALFTONEHINTS:\n\t\ttd->td_halftonehints[0] = (uint16) va_arg(ap, uint16_vap);\n\t\ttd->td_halftonehints[1] = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_COLORMAP:\n\t\tv32 = (uint32)(1L<<td->td_bitspersample);\n\t\t_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);\n\t\t_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);\n\t\t_TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);\n\t\tbreak;\n\tcase TIFFTAG_EXTRASAMPLES:\n\t\tif (!setExtraSamples(td, ap, &v))\n\t\t\tgoto badvalue;\n\t\tbreak;\n\tcase TIFFTAG_MATTEING:\n\t\ttd->td_extrasamples =  (((uint16) va_arg(ap, uint16_vap)) != 0);\n\t\tif (td->td_extrasamples) {\n\t\t\tuint16 sv = EXTRASAMPLE_ASSOCALPHA;\n\t\t\t_TIFFsetShortArray(&td->td_sampleinfo, &sv, 1);\n\t\t}\n\t\tbreak;\n\tcase TIFFTAG_TILEWIDTH:\n\t\tv32 = (uint32) va_arg(ap, uint32);\n\t\tif (v32 % 16) {\n\t\t\tif (tif->tif_mode != O_RDONLY)\n\t\t\t\tgoto badvalue32;\n\t\t\tTIFFWarningExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t"Nonstandard tile width %d, convert file", v32);\n\t\t}\n\t\ttd->td_tilewidth = v32;\n\t\ttif->tif_flags |= TIFF_ISTILED;\n\t\tbreak;\n\tcase TIFFTAG_TILELENGTH:\n\t\tv32 = (uint32) va_arg(ap, uint32);\n\t\tif (v32 % 16) {\n\t\t\tif (tif->tif_mode != O_RDONLY)\n\t\t\t\tgoto badvalue32;\n\t\t\tTIFFWarningExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t    "Nonstandard tile length %d, convert file", v32);\n\t\t}\n\t\ttd->td_tilelength = v32;\n\t\ttif->tif_flags |= TIFF_ISTILED;\n\t\tbreak;\n\tcase TIFFTAG_TILEDEPTH:\n\t\tv32 = (uint32) va_arg(ap, uint32);\n\t\tif (v32 == 0)\n\t\t\tgoto badvalue32;\n\t\ttd->td_tiledepth = v32;\n\t\tbreak;\n\tcase TIFFTAG_DATATYPE:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tswitch (v) {\n\t\tcase DATATYPE_VOID:\tv = SAMPLEFORMAT_VOID;\tbreak;\n\t\tcase DATATYPE_INT:\tv = SAMPLEFORMAT_INT;\tbreak;\n\t\tcase DATATYPE_UINT:\tv = SAMPLEFORMAT_UINT;\tbreak;\n\t\tcase DATATYPE_IEEEFP:\tv = SAMPLEFORMAT_IEEEFP;break;\n\t\tdefault:\t\tgoto badvalue;\n\t\t}\n\t\ttd->td_sampleformat = (uint16) v;\n\t\tbreak;\n\tcase TIFFTAG_SAMPLEFORMAT:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\tif (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v)\n\t\t\tgoto badvalue;\n\t\ttd->td_sampleformat = (uint16) v;\n\t\tif( td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT\n\t\t    && td->td_bitspersample == 32\n\t\t    && tif->tif_postdecode == _TIFFSwab32BitData )\n\t\t    tif->tif_postdecode = _TIFFSwab16BitData;\n\t\telse if( (td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT\n\t\t\t  || td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP)\n\t\t\t && td->td_bitspersample == 64\n\t\t\t && tif->tif_postdecode == _TIFFSwab64BitData )\n\t\t    tif->tif_postdecode = _TIFFSwab32BitData;\n\t\tbreak;\n\tcase TIFFTAG_IMAGEDEPTH:\n\t\ttd->td_imagedepth = (uint32) va_arg(ap, uint32);\n\t\tbreak;\n\tcase TIFFTAG_SUBIFD:\n\t\tif ((tif->tif_flags & TIFF_INSUBIFD) == 0) {\n\t\t\ttd->td_nsubifd = (uint16) va_arg(ap, uint16_vap);\n\t\t\t_TIFFsetLong8Array(&td->td_subifd, (uint64*) va_arg(ap, uint64*),\n\t\t\t    (long) td->td_nsubifd);\n\t\t} else {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t     "%s: Sorry, cannot nest SubIFDs",\n\t\t\t\t     tif->tif_name);\n\t\t\tstatus = 0;\n\t\t}\n\t\tbreak;\n\tcase TIFFTAG_YCBCRPOSITIONING:\n\t\ttd->td_ycbcrpositioning = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_YCBCRSUBSAMPLING:\n\t\ttd->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, uint16_vap);\n\t\ttd->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, uint16_vap);\n\t\tbreak;\n\tcase TIFFTAG_TRANSFERFUNCTION:\n\t\tv = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1;\n\t\tfor (i = 0; i < v; i++)\n\t\t\t_TIFFsetShortArray(&td->td_transferfunction[i],\n\t\t\t    va_arg(ap, uint16*), 1L<<td->td_bitspersample);\n\t\tbreak;\n\tcase TIFFTAG_INKNAMES:\n\t\tv = (uint16) va_arg(ap, uint16_vap);\n\t\ts = va_arg(ap, char*);\n\t\tv = checkInkNamesString(tif, v, s);\n\t\tstatus = v > 0;\n\t\tif( v > 0 ) {\n\t\t\t_TIFFsetNString(&td->td_inknames, s, v);\n\t\t\ttd->td_inknameslen = v;\n\t\t}\n\t\tbreak;\n\tdefault: {\n\t\tTIFFTagValue *tv;\n\t\tint tv_size, iCustom;\n\t\tconst TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);\n\t\tif(fip == NULL || fip->field_bit != FIELD_CUSTOM) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t    "%s: Invalid %stag \\"%s\\" (not supported by codec)",\n\t\t\t    tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",\n\t\t\t    fip ? fip->field_name : "Unknown");\n\t\t\tstatus = 0;\n\t\t\tbreak;\n\t\t}\n\t\ttv = NULL;\n\t\tfor (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) {\n\t\t\tif (td->td_customValues[iCustom].info->field_tag == tag) {\n\t\t\t\ttv = td->td_customValues + iCustom;\n\t\t\t\tif (tv->value != NULL) {\n\t\t\t\t\t_TIFFfree(tv->value);\n\t\t\t\t\ttv->value = NULL;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(tv == NULL) {\n\t\t\tTIFFTagValue *new_customValues;\n\t\t\ttd->td_customValueCount++;\n\t\t\tnew_customValues = (TIFFTagValue *)\n\t\t\t    _TIFFrealloc(td->td_customValues,\n\t\t\t    sizeof(TIFFTagValue) * td->td_customValueCount);\n\t\t\tif (!new_customValues) {\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t    "%s: Failed to allocate space for list of custom values",\n\t\t\t\t    tif->tif_name);\n\t\t\t\tstatus = 0;\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\ttd->td_customValues = new_customValues;\n\t\t\ttv = td->td_customValues + (td->td_customValueCount - 1);\n\t\t\ttv->info = fip;\n\t\t\ttv->value = NULL;\n\t\t\ttv->count = 0;\n\t\t}\n\t\ttv_size = _TIFFDataSize(fip->field_type);\n\t\tif (tv_size == 0) {\n\t\t\tstatus = 0;\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t    "%s: Bad field type %d for \\"%s\\"",\n\t\t\t    tif->tif_name, fip->field_type,\n\t\t\t    fip->field_name);\n\t\t\tgoto end;\n\t\t}\n\t\tif (fip->field_type == TIFF_ASCII)\n\t\t{\n\t\t\tuint32 ma;\n\t\t\tchar* mb;\n\t\t\tif (fip->field_passcount)\n\t\t\t{\n\t\t\t\tassert(fip->field_writecount==TIFF_VARIABLE2);\n\t\t\t\tma=(uint32)va_arg(ap,uint32);\n\t\t\t\tmb=(char*)va_arg(ap,char*);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmb=(char*)va_arg(ap,char*);\n\t\t\t\tma=(uint32)(strlen(mb)+1);\n\t\t\t}\n\t\t\ttv->count=ma;\n\t\t\tsetByteArray(&tv->value,mb,ma,1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(fip->field_passcount) {\n\t\t\t\tif (fip->field_writecount == TIFF_VARIABLE2)\n\t\t\t\t\ttv->count = (uint32) va_arg(ap, uint32);\n\t\t\t\telse\n\t\t\t\t\ttv->count = (int) va_arg(ap, int);\n\t\t\t} else if (fip->field_writecount == TIFF_VARIABLE\n\t\t\t   || fip->field_writecount == TIFF_VARIABLE2)\n\t\t\t\ttv->count = 1;\n\t\t\telse if (fip->field_writecount == TIFF_SPP)\n\t\t\t\ttv->count = td->td_samplesperpixel;\n\t\t\telse\n\t\t\t\ttv->count = fip->field_writecount;\n\t\t\ttv->value = _TIFFCheckMalloc(tif, tv_size, tv->count,\n\t\t\t    "Tag Value");\n\t\t\tif (!tv->value) {\n\t\t\t\tstatus = 0;\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\tif ((fip->field_passcount\n\t\t\t    || fip->field_writecount == TIFF_VARIABLE\n\t\t\t    || fip->field_writecount == TIFF_VARIABLE2\n\t\t\t    || fip->field_writecount == TIFF_SPP\n\t\t\t    || tv->count > 1)\n\t\t\t    && fip->field_tag != TIFFTAG_PAGENUMBER\n\t\t\t    && fip->field_tag != TIFFTAG_HALFTONEHINTS\n\t\t\t    && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING\n\t\t\t    && fip->field_tag != TIFFTAG_DOTRANGE) {\n\t\t\t\t_TIFFmemcpy(tv->value, va_arg(ap, void *),\n\t\t\t\t    tv->count * tv_size);\n\t\t\t} else {\n\t\t\t\tint i;\n\t\t\t\tchar *val = (char *)tv->value;\n\t\t\t\tfor (i = 0; i < tv->count; i++, val += tv_size) {\n\t\t\t\t\tswitch (fip->field_type) {\n\t\t\t\t\t\tcase TIFF_BYTE:\n\t\t\t\t\t\tcase TIFF_UNDEFINED:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tuint8 v = (uint8)va_arg(ap, int);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_SBYTE:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint8 v = (int8)va_arg(ap, int);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_SHORT:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tuint16 v = (uint16)va_arg(ap, int);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_SSHORT:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint16 v = (int16)va_arg(ap, int);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_LONG:\n\t\t\t\t\t\tcase TIFF_IFD:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tuint32 v = va_arg(ap, uint32);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_SLONG:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint32 v = va_arg(ap, int32);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_LONG8:\n\t\t\t\t\t\tcase TIFF_IFD8:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tuint64 v = va_arg(ap, uint64);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_SLONG8:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint64 v = va_arg(ap, int64);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_RATIONAL:\n\t\t\t\t\t\tcase TIFF_SRATIONAL:\n\t\t\t\t\t\tcase TIFF_FLOAT:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfloat v = (float)va_arg(ap, double);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase TIFF_DOUBLE:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdouble v = va_arg(ap, double);\n\t\t\t\t\t\t\t\t_TIFFmemcpy(val, &v, tv_size);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t_TIFFmemset(val, 0, tv_size);\n\t\t\t\t\t\t\tstatus = 0;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t}\n\tif (status) {\n\t\tTIFFSetFieldBit(tif, TIFFFieldWithTag(tif, tag)->field_bit);\n\t\ttif->tif_flags |= TIFF_DIRTYDIRECT;\n\t}\nend:\n\tva_end(ap);\n\treturn (status);\nbadvalue:\n\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t     "%s: Bad value %u for \\"%s\\" tag",\n\t\t     tif->tif_name, v,\n\t\t     TIFFFieldWithTag(tif, tag)->field_name);\n\tva_end(ap);\n\treturn (0);\nbadvalue32:\n\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t     "%s: Bad value %u for \\"%s\\" tag",\n\t\t     tif->tif_name, v32,\n\t\t     TIFFFieldWithTag(tif, tag)->field_name);\n\tva_end(ap);\n\treturn (0);\n}', 'void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)\n    { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }', 'static void\nsetByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)\n{\n\tif (*vpp)\n\t\t_TIFFfree(*vpp), *vpp = 0;\n\tif (vp) {\n\t\ttmsize_t bytes = (tmsize_t)(nmemb * elem_size);\n\t\tif (elem_size && bytes / elem_size == nmemb)\n\t\t\t*vpp = (void*) _TIFFmalloc(bytes);\n\t\tif (*vpp)\n\t\t\t_TIFFmemcpy(*vpp, vp, bytes);\n\t}\n}', 'void\n_TIFFfree(void* p)\n{\n\tfree(p);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n\treturn (malloc((size_t) s));\n}', 'void\n_TIFFmemcpy(void* d, const void* s, tmsize_t c)\n{\n\tmemcpy(d, s, (size_t) c);\n}']