libtiff/tif_dir.c:286: error: Memory Leak
  memory dynamically allocated by call to `_TIFFsetShortArray()` at line 285, column 3 is not reachable after line 286, 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:182:2: Switch condition is false. Skipping switch case
180. 		}
181. 		break;
182. 	case TIFFTAG_COMPRESSION:
      ^
183. 		v = (uint16) va_arg(ap, uint16_vap);
184. 		/*

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

libtiff/tif_dir.c:284:3: 
282. 	case TIFFTAG_COLORMAP:
283. 		v32 = (uint32)(1L<<td->td_bitspersample);
284. 		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
       ^
285. 		_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);
286. 		_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:285:3: 
283. 		v32 = (uint32)(1L<<td->td_bitspersample);
284. 		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
285. 		_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);
       ^
286. 		_TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);
287. 		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 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:286:3: 
284. 		_TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
285. 		_TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);
286. 		_TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);
       ^
287. 		break;
288. 	case TIFFTAG_EXTRASAMPLES:

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 == 8)
				tif->tif_postdecode = _TIFFNoPostDecode;
			else 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_REFERENCEBLACKWHITE:
		_TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
		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;
			if (tv->count == 0) {
				status = 0;
				TIFFErrorExt(tif->tif_clientdata, module,
					     "%s: Null count for \"%s\" (type "
					     "%d, writecount %d, passcount %d)",
					     tif->tif_name,
					     fip->field_name,
					     fip->field_type,
					     fip->field_writecount,
					     fip->field_passcount);
				goto end;
			}
			tv->value = _TIFFCheckMalloc(tif, tv->count, tv_size,
			    "custom tag binary object");
			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 == 8)\n\t\t\t\ttif->tif_postdecode = _TIFFNoPostDecode;\n\t\t\telse if (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_REFERENCEBLACKWHITE:\n\t\t_TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);\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\tif (tv->count == 0) {\n\t\t\t\tstatus = 0;\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t     "%s: Null count for \\"%s\\" (type "\n\t\t\t\t\t     "%d, writecount %d, passcount %d)",\n\t\t\t\t\t     tif->tif_name,\n\t\t\t\t\t     fip->field_name,\n\t\t\t\t\t     fip->field_type,\n\t\t\t\t\t     fip->field_writecount,\n\t\t\t\t\t     fip->field_passcount);\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\ttv->value = _TIFFCheckMalloc(tif, tv->count, tv_size,\n\t\t\t    "custom tag binary object");\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}']