int ST_SetKey( ST_TIFF *st, int tag, int count, int st_type, void *data ) { int i, item_size = ST_TypeSize( st_type ); /* -------------------------------------------------------------------- */ /* If we already have a value for this tag, replace it. */ /* -------------------------------------------------------------------- */ for( i = 0; i < st->key_count; i++ ) { if( st->key_list[i].tag == tag ) { free( st->key_list[i].data ); st->key_list[i].count = count; st->key_list[i].type = st_type; st->key_list[i].data = malloc(item_size*count); memcpy( st->key_list[i].data, data, count * item_size ); return 1; } } /* -------------------------------------------------------------------- */ /* Otherwise, add a new entry. */ /* -------------------------------------------------------------------- */ st->key_count++; st->key_list = (ST_KEY *) realloc(st->key_list, sizeof(ST_KEY) * st->key_count); st->key_list[st->key_count-1].tag = tag; st->key_list[st->key_count-1].count = count; st->key_list[st->key_count-1].type = st_type; st->key_list[st->key_count-1].data = malloc(item_size * count); memcpy( st->key_list[st->key_count-1].data, data, item_size * count ); return 1; }
int ST_SetKey( ST_TIFF *st, int tag, int count, int st_type, void *data ) { int i, item_size = ST_TypeSize( st_type ); /* -------------------------------------------------------------------- */ /* We should compute the length if we were not given a count */ /* -------------------------------------------------------------------- */ if (count == 0 && st_type == STT_ASCII ) { count = (int)strlen((char*)data)+1; } /* -------------------------------------------------------------------- */ /* If we already have a value for this tag, replace it. */ /* -------------------------------------------------------------------- */ for( i = 0; i < st->key_count; i++ ) { if( st->key_list[i].tag == tag ) { free( st->key_list[i].data ); st->key_list[i].count = count; st->key_list[i].type = st_type; /* +1 to make clang static analyzer not warn about potential malloc(0) */ st->key_list[i].data = malloc(item_size*count+1); memcpy( st->key_list[i].data, data, count * item_size ); return 1; } } /* -------------------------------------------------------------------- */ /* Otherwise, add a new entry. */ /* -------------------------------------------------------------------- */ st->key_count++; st->key_list = (ST_KEY *) realloc(st->key_list, sizeof(ST_KEY) * st->key_count); st->key_list[st->key_count-1].tag = tag; st->key_list[st->key_count-1].count = count; st->key_list[st->key_count-1].type = st_type; /* +1 to make clang static analyzer not warn about potential malloc(0) */ st->key_list[st->key_count-1].data = malloc(item_size * count+1); memcpy( st->key_list[st->key_count-1].data, data, item_size * count ); return 1; }
/* returns the value of TIFF tag <tag>, or if * the value is an array, returns an allocated buffer * containing the values. Allocate a copy of the actual * buffer, sized up for updating. */ static int _GTIFGetField (tiff_t *tif, pinfo_t tag, int *count, void *val ) { int item_size, data_type; void *internal_value, *ret_value; if( !ST_GetKey( (ST_TIFF*) tif, (int) tag, count, &data_type, &internal_value ) ) return 0; if( data_type != ST_TagType( tag ) ) return 0; item_size = ST_TypeSize( data_type ); ret_value = (char *)_GTIFcalloc( *count * item_size ); if (!ret_value) return 0; _TIFFmemcpy( ret_value, internal_value, item_size * *count ); *(void **)val = ret_value; return 1; }