]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/exif: Avoid allocation for small buffer
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 23 Jan 2021 14:44:50 +0000 (15:44 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 26 Jan 2021 12:56:59 +0000 (13:56 +0100)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/exif.c

index 2874772db4d7d1b282ddcdaf3868e24e8134b827..0b656fd09b270e25bc385a1be8e9dc1f596c8344 100644 (file)
@@ -95,22 +95,15 @@ static int exif_decode_tag(void *logctx, GetByteContext *gbytes, int le,
         ret = ff_exif_decode_ifd(logctx, gbytes, le, depth + 1, metadata);
     } else {
         const char *name = exif_get_tag_name(id);
-        char *use_name   = (char*) name;
-
-        if (!use_name) {
-            use_name = av_malloc(7);
-            if (!use_name) {
-                return AVERROR(ENOMEM);
-            }
-            snprintf(use_name, 7, "0x%04X", id);
-        }
-
-        ret = exif_add_metadata(logctx, count, type, use_name, NULL,
-                                gbytes, le, metadata);
+        char buf[7];
 
         if (!name) {
-            av_freep(&use_name);
+            name = buf;
+            snprintf(buf, sizeof(buf), "0x%04X", id);
         }
+
+        ret = exif_add_metadata(logctx, count, type, name, NULL,
+                                gbytes, le, metadata);
     }
 
     bytestream2_seek(gbytes, cur_pos, SEEK_SET);