int _TIFFMergeFields(TIFF* tif, const TIFFField info[], uint32 n) { static const char module[] = "_TIFFMergeFields"; static const char reason[] = "for fields array"; /* TIFFField** tp; */ uint32 i; tif->tif_foundfield = NULL; if (tif->tif_fields && tif->tif_nfields > 0) { tif->tif_fields = (TIFFField**) _TIFFCheckRealloc(tif, tif->tif_fields, (tif->tif_nfields + n), sizeof(TIFFField *), reason); } else { tif->tif_fields = (TIFFField **) _TIFFCheckMalloc(tif, n, sizeof(TIFFField *), reason); } if (!tif->tif_fields) { TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate fields array"); return 0; } /* tp = tif->tif_fields + tif->tif_nfields; */ 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, sizeof(TIFFField *), tagCompare); return n; }
int _TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], int n) { static const char module[] = "_TIFFMergeFieldInfo"; static const char reason[] = "for field info array"; TIFFFieldInfo** tp; int i; tif->tif_foundfield = NULL; if (tif->tif_nfields > 0) { tif->tif_fieldinfo = (TIFFFieldInfo**) _TIFFCheckRealloc(tif, tif->tif_fieldinfo, (tif->tif_nfields + n), sizeof (TIFFFieldInfo*), reason); } else { tif->tif_fieldinfo = (TIFFFieldInfo**) _TIFFCheckMalloc(tif, n, sizeof (TIFFFieldInfo*), reason); } if (!tif->tif_fieldinfo) { TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate field info array"); return 0; } tp = tif->tif_fieldinfo + tif->tif_nfields; for (i = 0; i < n; i++) { const TIFFFieldInfo *fip = _TIFFFindFieldInfo(tif, info[i].field_tag, info[i].field_type); /* only add definitions that aren't already present */ if (!fip) { *tp++ = (TIFFFieldInfo*) (info + i); tif->tif_nfields++; } } /* Sort the field info by tag number */ qsort(tif->tif_fieldinfo, tif->tif_nfields, sizeof (TIFFFieldInfo*), tagCompare); return n; }
int TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) { static const char module[] = "TIFFMergeFieldInfo"; static const char reason[] = "for fields array"; TIFFField *tp; size_t nfields; uint32 i; if (tif->tif_nfieldscompat > 0) { tif->tif_fieldscompat = (TIFFFieldArray *) _TIFFCheckRealloc(tif, tif->tif_fieldscompat, tif->tif_nfieldscompat + 1, sizeof(TIFFFieldArray), reason); } else { tif->tif_fieldscompat = (TIFFFieldArray *) _TIFFCheckMalloc(tif, 1, sizeof(TIFFFieldArray), reason); } if (!tif->tif_fieldscompat) { TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate fields array"); return -1; } nfields = tif->tif_nfieldscompat++; tif->tif_fieldscompat[nfields].type = tfiatOther; tif->tif_fieldscompat[nfields].allocated_size = n; tif->tif_fieldscompat[nfields].count = n; tif->tif_fieldscompat[nfields].fields = (TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField), reason); if (!tif->tif_fieldscompat[nfields].fields) { TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate fields array"); return -1; } tp = tif->tif_fieldscompat[nfields].fields; for (i = 0; i < n; i++) { tp->field_tag = info[i].field_tag; tp->field_readcount = info[i].field_readcount; tp->field_writecount = info[i].field_writecount; tp->field_type = info[i].field_type; tp->reserved = 0; tp->set_field_type = _TIFFSetGetType(info[i].field_type, info[i].field_readcount, info[i].field_passcount); tp->get_field_type = _TIFFSetGetType(info[i].field_type, info[i].field_readcount, info[i].field_passcount); tp->field_bit = info[i].field_bit; tp->field_oktochange = info[i].field_oktochange; tp->field_passcount = info[i].field_passcount; tp->field_name = info[i].field_name; tp->field_subfields = NULL; tp++; } if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n)) { TIFFErrorExt(tif->tif_clientdata, module, "Setting up field info failed"); return -1; } return 0; }
void* _TIFFCheckMalloc(TIFF* tif, tmsize_t nmemb, tmsize_t elem_size, const char* what) { return _TIFFCheckRealloc(tif, NULL, nmemb, elem_size, what); }