avcodec/tiff_common: Fix AVBPrint error checks

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/365/head
Andreas Rheinhardt 3 years ago
parent b2d61d0f02
commit 9634e6b0b0
  1. 76
      libavcodec/tiff_common.c

@ -80,11 +80,26 @@ static const char *auto_sep(int count, const char *sep, int i, int columns)
return columns < count ? "\n" : ""; return columns < count ? "\n" : "";
} }
static int bprint_to_avdict(AVBPrint *bp, const char *name,
AVDictionary **metadata)
{
char *ap;
int ret;
if (!av_bprint_is_complete(bp)) {
av_bprint_finalize(bp, NULL);
return AVERROR(ENOMEM);
}
if ((ret = av_bprint_finalize(bp, &ap)) < 0)
return ret;
return av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
}
int ff_tadd_rational_metadata(int count, const char *name, const char *sep, int ff_tadd_rational_metadata(int count, const char *name, const char *sep,
GetByteContext *gb, int le, AVDictionary **metadata) GetByteContext *gb, int le, AVDictionary **metadata)
{ {
AVBPrint bp; AVBPrint bp;
char *ap;
int32_t nom, denom; int32_t nom, denom;
int i; int i;
@ -101,16 +116,7 @@ int ff_tadd_rational_metadata(int count, const char *name, const char *sep,
av_bprintf(&bp, "%s%7"PRId32":%-7"PRId32, auto_sep(count, sep, i, 4), nom, denom); av_bprintf(&bp, "%s%7"PRId32":%-7"PRId32, auto_sep(count, sep, i, 4), nom, denom);
} }
if ((i = av_bprint_finalize(&bp, &ap))) { return bprint_to_avdict(&bp, name, metadata);
return i;
}
if (!ap) {
return AVERROR(ENOMEM);
}
av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
return 0;
} }
@ -118,7 +124,6 @@ int ff_tadd_long_metadata(int count, const char *name, const char *sep,
GetByteContext *gb, int le, AVDictionary **metadata) GetByteContext *gb, int le, AVDictionary **metadata)
{ {
AVBPrint bp; AVBPrint bp;
char *ap;
int i; int i;
if (count >= INT_MAX / sizeof(int32_t) || count <= 0) if (count >= INT_MAX / sizeof(int32_t) || count <= 0)
@ -132,16 +137,7 @@ int ff_tadd_long_metadata(int count, const char *name, const char *sep,
av_bprintf(&bp, "%s%7i", auto_sep(count, sep, i, 8), ff_tget_long(gb, le)); av_bprintf(&bp, "%s%7i", auto_sep(count, sep, i, 8), ff_tget_long(gb, le));
} }
if ((i = av_bprint_finalize(&bp, &ap))) { return bprint_to_avdict(&bp, name, metadata);
return i;
}
if (!ap) {
return AVERROR(ENOMEM);
}
av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
return 0;
} }
@ -149,7 +145,6 @@ int ff_tadd_doubles_metadata(int count, const char *name, const char *sep,
GetByteContext *gb, int le, AVDictionary **metadata) GetByteContext *gb, int le, AVDictionary **metadata)
{ {
AVBPrint bp; AVBPrint bp;
char *ap;
int i; int i;
if (count >= INT_MAX / sizeof(int64_t) || count <= 0) if (count >= INT_MAX / sizeof(int64_t) || count <= 0)
@ -163,16 +158,7 @@ int ff_tadd_doubles_metadata(int count, const char *name, const char *sep,
av_bprintf(&bp, "%s%.15g", auto_sep(count, sep, i, 4), ff_tget_double(gb, le)); av_bprintf(&bp, "%s%.15g", auto_sep(count, sep, i, 4), ff_tget_double(gb, le));
} }
if ((i = av_bprint_finalize(&bp, &ap))) { return bprint_to_avdict(&bp, name, metadata);
return i;
}
if (!ap) {
return AVERROR(ENOMEM);
}
av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
return 0;
} }
@ -180,7 +166,6 @@ int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
GetByteContext *gb, int le, int is_signed, AVDictionary **metadata) GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
{ {
AVBPrint bp; AVBPrint bp;
char *ap;
int i; int i;
if (count >= INT_MAX / sizeof(int16_t) || count <= 0) if (count >= INT_MAX / sizeof(int16_t) || count <= 0)
@ -195,16 +180,7 @@ int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
av_bprintf(&bp, "%s%5i", auto_sep(count, sep, i, 8), v); av_bprintf(&bp, "%s%5i", auto_sep(count, sep, i, 8), v);
} }
if ((i = av_bprint_finalize(&bp, &ap))) { return bprint_to_avdict(&bp, name, metadata);
return i;
}
if (!ap) {
return AVERROR(ENOMEM);
}
av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
return 0;
} }
@ -212,7 +188,6 @@ int ff_tadd_bytes_metadata(int count, const char *name, const char *sep,
GetByteContext *gb, int le, int is_signed, AVDictionary **metadata) GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
{ {
AVBPrint bp; AVBPrint bp;
char *ap;
int i; int i;
if (count >= INT_MAX / sizeof(int8_t) || count < 0) if (count >= INT_MAX / sizeof(int8_t) || count < 0)
@ -227,16 +202,7 @@ int ff_tadd_bytes_metadata(int count, const char *name, const char *sep,
av_bprintf(&bp, "%s%3i", auto_sep(count, sep, i, 16), v); av_bprintf(&bp, "%s%3i", auto_sep(count, sep, i, 16), v);
} }
if ((i = av_bprint_finalize(&bp, &ap))) { return bprint_to_avdict(&bp, name, metadata);
return i;
}
if (!ap) {
return AVERROR(ENOMEM);
}
av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
return 0;
} }
int ff_tadd_string_metadata(int count, const char *name, int ff_tadd_string_metadata(int count, const char *name,

Loading…
Cancel
Save