_TIFFMergeFields() now only merges in field definitions that are missing.

Existing definitions are silently ignored.  This avoids warnings with
multi-directory files.
This commit is contained in:
Frank Warmerdam 2007-08-24 20:47:49 +00:00
parent 4baacb150b
commit a6bea11162
2 changed files with 17 additions and 16 deletions

View File

@ -1,5 +1,9 @@
2007-08-24 Frank Warmerdam <warmerdam@pobox.com>
* 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

View File

@ -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;