diff mbox series

[FFmpeg-devel,2.2/3] libavformat/protocols.c: avio_enum_protocols(): Convert recursion to iteration

Message ID a61ac7edf97b437ca9aa72a4a3cfc71b@gmail.com
State New
Headers show
Series [FFmpeg-devel,2.1/3] libavformat/protocols.c: avio_enum_protocols(): Split declaration and initialization | expand


Context Check Description
andriy/configure warning Failed to apply patch

Commit Message

Michael Witten Aug. 11, 2021, 7 p.m. UTC
In C, it's generally not good to write a recursive algorithm,
because it is not possible to rely on the compiler to elide
a tail call; therefore, this commit converts a tail call into
an iterative loop by means of an explicit 'goto' statement.
 libavformat/protocols.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 1c5e3b2bdb..b0aae66dab 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -95,6 +95,7 @@  const char *avio_enum_protocols(void **const opaque, const int output)
     const URLProtocol *const *p;
     p = *opaque;
     p = p ? p + 1 : url_protocols;
     *opaque = (void *)p;
@@ -104,7 +105,7 @@  const char *avio_enum_protocols(void **const opaque, const int output)
     if ((output && (*p)->url_write) || (!output && (*p)->url_read))
         return (*p)->name;
-    return avio_enum_protocols(opaque, output);
+    goto iterate;
 const AVClass *avio_protocol_get_class(const char *name)