[FFmpeg-cvslog] lavf/protocols: avoid discarding const in avio_enum_protocols()

Anton Khirnov git at videolan.org
Tue Dec 7 12:18:25 EET 2021


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Nov 25 15:40:16 2021 +0100| [6ebaccf327ce0fd88555fdd8b3f3deb019f0dc98] | committer: Anton Khirnov

lavf/protocols: avoid discarding const in avio_enum_protocols()

Instead of storing the protocol pointer in the opaque iteration state,
store just the index of the next protocol, similarly to how
ff_urlcontext_child_class_iterate() works.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6ebaccf327ce0fd88555fdd8b3f3deb019f0dc98
---

 libavformat/protocols.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index b108aa6c7e..948fae411f 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -93,17 +93,17 @@ const AVClass *ff_urlcontext_child_class_iterate(void **iter)
 
 const char *avio_enum_protocols(void **opaque, int output)
 {
-    const URLProtocol **p = *opaque;
+    uintptr_t i;
 
-    p = p ? p + 1 : url_protocols;
-    *opaque = p;
-    if (!*p) {
-        *opaque = NULL;
-        return NULL;
+    for (i = (uintptr_t)*opaque; url_protocols[i]; i++) {
+        const URLProtocol *p = url_protocols[i];
+        if ((output && p->url_write) || (!output && p->url_read)) {
+            *opaque = (void*)(uintptr_t)(i + 1);
+            return p->name;
+        }
     }
-    if ((output && (*p)->url_write) || (!output && (*p)->url_read))
-        return (*p)->name;
-    return avio_enum_protocols(opaque, output);
+    *opaque = NULL;
+    return NULL;
 }
 
 const AVClass *avio_protocol_get_class(const char *name)



More information about the ffmpeg-cvslog mailing list