aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-08-25 09:31:16 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-08-30 15:48:11 +0200
commit9634e6b0b065896bfc02cce4b1687a22531e2ecf (patch)
treebef8a1c8af49ea855548f594546a4ea6bfbdb115
parentb2d61d0f02199be2d3d2b57a6bd1b4121b7b9bd1 (diff)
downloadffmpeg-9634e6b0b065896bfc02cce4b1687a22531e2ecf.tar.gz
avcodec/tiff_common: Fix AVBPrint error checks
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/tiff_common.c76
1 files changed, 21 insertions, 55 deletions
diff --git a/libavcodec/tiff_common.c b/libavcodec/tiff_common.c
index b3c6b96b57..2b872ea7e2 100644
--- a/libavcodec/tiff_common.c
+++ b/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" : "";
}
+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,
GetByteContext *gb, int le, AVDictionary **metadata)
{
AVBPrint bp;
- char *ap;
int32_t nom, denom;
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);
}
- if ((i = av_bprint_finalize(&bp, &ap))) {
- return i;
- }
- if (!ap) {
- return AVERROR(ENOMEM);
- }
-
- av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
-
- return 0;
+ return bprint_to_avdict(&bp, name, metadata);
}
@@ -118,7 +124,6 @@ int ff_tadd_long_metadata(int count, const char *name, const char *sep,
GetByteContext *gb, int le, AVDictionary **metadata)
{
AVBPrint bp;
- char *ap;
int i;
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));
}
- if ((i = av_bprint_finalize(&bp, &ap))) {
- return i;
- }
- if (!ap) {
- return AVERROR(ENOMEM);
- }
-
- av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
-
- return 0;
+ return bprint_to_avdict(&bp, name, metadata);
}
@@ -149,7 +145,6 @@ int ff_tadd_doubles_metadata(int count, const char *name, const char *sep,
GetByteContext *gb, int le, AVDictionary **metadata)
{
AVBPrint bp;
- char *ap;
int i;
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));
}
- if ((i = av_bprint_finalize(&bp, &ap))) {
- return i;
- }
- if (!ap) {
- return AVERROR(ENOMEM);
- }
-
- av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
-
- return 0;
+ return bprint_to_avdict(&bp, name, metadata);
}
@@ -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)
{
AVBPrint bp;
- char *ap;
int i;
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);
}
- if ((i = av_bprint_finalize(&bp, &ap))) {
- return i;
- }
- if (!ap) {
- return AVERROR(ENOMEM);
- }
-
- av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
-
- return 0;
+ return bprint_to_avdict(&bp, name, metadata);
}
@@ -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)
{
AVBPrint bp;
- char *ap;
int i;
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);
}
- if ((i = av_bprint_finalize(&bp, &ap))) {
- return i;
- }
- if (!ap) {
- return AVERROR(ENOMEM);
- }
-
- av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
-
- return 0;
+ return bprint_to_avdict(&bp, name, metadata);
}
int ff_tadd_string_metadata(int count, const char *name,