From a6bea11162768ecdda2deb623ed676e022a119ee Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Fri, 24 Aug 2007 20:47:49 +0000 Subject: [PATCH] _TIFFMergeFields() now only merges in field definitions that are missing. Existing definitions are silently ignored. This avoids warnings with multi-directory files. --- ChangeLog | 4 ++++ libtiff/tif_dirinfo.c | 29 +++++++++++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc298da9..ccc87336 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2007-08-24 Frank Warmerdam + * tif_dirinfo.c: _TIFFMergeFields() now only merges in field + definitions that are missing. Existing definitions are silently + ignored. + * tif_dirread.c: Add runtime error for fields for which no definition is found (in addition to an assert for developers) in TIFFFetchNormalTag(). Not sure if this is needed, but it seems diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index 2fa01af0..0c383f14 100644 --- a/libtiff/tif_dirinfo.c +++ b/libtiff/tif_dirinfo.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirinfo.c,v 1.94 2007-07-19 17:16:25 dron Exp $ */ +/* $Id: tif_dirinfo.c,v 1.95 2007-08-24 20:47:49 fwarmerdam Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -330,18 +330,6 @@ _TIFFMergeFields(TIFF* tif, const TIFFField info[], uint32 n) TIFFField** tp; uint32 i; - for (i = 0; i < n; i++) { - const TIFFField *fip = - TIFFFindField(tif, info[i].field_tag, TIFF_ANY); - if (fip) { - TIFFErrorExt(tif->tif_clientdata, module, - "Field with tag %lu is already registered as \"%s\"", - (unsigned int) info[i].field_tag, - fip->field_name); - return 0; - } - } - tif->tif_foundfield = NULL; if (tif->tif_fields && tif->tif_nfields > 0) { @@ -359,12 +347,21 @@ _TIFFMergeFields(TIFF* tif, const TIFFField info[], uint32 n) "Failed to allocate fields array"); return 0; } + tp = tif->tif_fields + tif->tif_nfields; - for (i = 0; i < n; i++) - *tp++ = (TIFFField *) (info + i); /* XXX */ + for (i = 0; i < n; i++) { + const TIFFField *fip = + TIFFFindField(tif, info[i].field_tag, TIFF_ANY); + + /* only add definitions that aren't already present */ + if (!fip) { + tif->tif_fields[tif->tif_nfields] = (TIFFField *) (info+i); + tif->tif_nfields++; + } + } /* Sort the field info by tag number */ - qsort(tif->tif_fields, tif->tif_nfields += n, + qsort(tif->tif_fields, tif->tif_nfields, sizeof(TIFFField *), tagCompare); return n;