diff mbox series

[FFmpeg-devel,09/10] avformat/md5proto: Simplify data->hex conversion

Message ID AM7PR03MB66603BA43C17B7D8825460CE8F6D9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit d203f6b4b33be409c85d5319f6cd253829334f45
Headers show
Series [FFmpeg-devel,01/10] avformat/utils: Make ff_data_to_hex() zero-terminate the string | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 6, 2021, 1:12 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/md5proto.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c
index 0e04b90aac..14cefe719c 100644
--- a/libavformat/md5proto.c
+++ b/libavformat/md5proto.c
@@ -25,6 +25,7 @@ 
 #include "libavutil/error.h"
 #include "avformat.h"
 #include "avio.h"
+#include "internal.h"
 #include "url.h"
 
 struct MD5Context {
@@ -57,14 +58,13 @@  static int md5_close(URLContext *h)
 {
     struct MD5Context *c = h->priv_data;
     const char *filename = h->filename;
-    uint8_t md5[16], buf[64];
+    uint8_t md5[16], buf[2 * sizeof(md5) + 1];
     URLContext *out;
-    int i, err = 0;
+    int err = 0;
 
     av_md5_final(c->md5, md5);
-    for (i = 0; i < sizeof(md5); i++)
-        snprintf(buf + i*2, 3, "%02x", md5[i]);
-    buf[i*2] = '\n';
+    ff_data_to_hex(buf, md5, sizeof(md5), 1);
+    buf[2 * sizeof(md5)] = '\n';
 
     av_strstart(filename, "md5:", &filename);
 
@@ -74,10 +74,10 @@  static int md5_close(URLContext *h)
                                    h->protocol_whitelist, h->protocol_blacklist, h);
         if (err)
             return err;
-        err = ffurl_write(out, buf, i*2+1);
+        err = ffurl_write(out, buf, sizeof(buf));
         ffurl_close(out);
     } else {
-        if (fwrite(buf, 1, i*2+1, stdout) < i*2+1)
+        if (fwrite(buf, 1, sizeof(buf), stdout) < sizeof(buf))
             err = AVERROR(errno);
     }