diff mbox series

[FFmpeg-devel,2/2] avformat/udp: remove local localaddr array

Message ID 1637837128-31393-2-git-send-email-lance.lmwang@gmail.com
State Accepted
Commit 27c930002702f512b80124249c5efbcc0ef04841
Headers show
Series [FFmpeg-devel,1/2] avformat/rtp: add localaddr for network interface selection | 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

Lance Wang Nov. 25, 2021, 10:45 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/udp.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Martin Storsjö Nov. 25, 2021, 10:54 a.m. UTC | #1
On Thu, 25 Nov 2021, lance.lmwang@gmail.com wrote:

> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavformat/udp.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index bbe5aec..b8b0e19 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -623,7 +623,7 @@ end:
> /* return non zero if error */
> static int udp_open(URLContext *h, const char *uri, int flags)
> {
> -    char hostname[1024], localaddr[1024] = "";
> +    char hostname[1024];
>     int port, udp_fd = -1, tmp, bind_ret = -1, dscp = -1;
>     UDPContext *s = h->priv_data;
>     int is_output;
> @@ -708,7 +708,8 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>             s->burst_bits = strtoll(buf, NULL, 10);
>         }
>         if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
> -            av_strlcpy(localaddr, buf, sizeof(localaddr));
> +            av_freep(&s->localaddr);
> +            s->localaddr = av_strdup(buf);
>         }
>         if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
>             if ((ret = ff_ip_parse_sources(h, buf, &s->filters)) < 0)
> @@ -748,10 +749,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>     if ((s->is_multicast || s->local_port <= 0) && (h->flags & AVIO_FLAG_READ))
>         s->local_port = port;
>
> -    if (localaddr[0])
> -        udp_fd = udp_socket_create(h, &my_addr, &len, localaddr);
> -    else
> -        udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
> +    udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
>     if (udp_fd < 0)
>         goto fail;
>
> -- 
> 1.8.3.1

This patch LGTM.

// Martin
Andreas Rheinhardt Nov. 26, 2021, 10:26 a.m. UTC | #2
lance.lmwang@gmail.com:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavformat/udp.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index bbe5aec..b8b0e19 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -623,7 +623,7 @@ end:
>  /* return non zero if error */
>  static int udp_open(URLContext *h, const char *uri, int flags)
>  {
> -    char hostname[1024], localaddr[1024] = "";
> +    char hostname[1024];
>      int port, udp_fd = -1, tmp, bind_ret = -1, dscp = -1;
>      UDPContext *s = h->priv_data;
>      int is_output;
> @@ -708,7 +708,8 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>              s->burst_bits = strtoll(buf, NULL, 10);
>          }
>          if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
> -            av_strlcpy(localaddr, buf, sizeof(localaddr));
> +            av_freep(&s->localaddr);
> +            s->localaddr = av_strdup(buf);

Missing check.

>          }
>          if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
>              if ((ret = ff_ip_parse_sources(h, buf, &s->filters)) < 0)
> @@ -748,10 +749,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>      if ((s->is_multicast || s->local_port <= 0) && (h->flags & AVIO_FLAG_READ))
>          s->local_port = port;
>  
> -    if (localaddr[0])
> -        udp_fd = udp_socket_create(h, &my_addr, &len, localaddr);
> -    else
> -        udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
> +    udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
>      if (udp_fd < 0)
>          goto fail;
>  
>
Lance Wang Nov. 26, 2021, 10:45 a.m. UTC | #3
On Fri, Nov 26, 2021 at 11:26:39AM +0100, Andreas Rheinhardt wrote:
> lance.lmwang@gmail.com:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavformat/udp.c | 10 ++++------
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> > 
> > diff --git a/libavformat/udp.c b/libavformat/udp.c
> > index bbe5aec..b8b0e19 100644
> > --- a/libavformat/udp.c
> > +++ b/libavformat/udp.c
> > @@ -623,7 +623,7 @@ end:
> >  /* return non zero if error */
> >  static int udp_open(URLContext *h, const char *uri, int flags)
> >  {
> > -    char hostname[1024], localaddr[1024] = "";
> > +    char hostname[1024];
> >      int port, udp_fd = -1, tmp, bind_ret = -1, dscp = -1;
> >      UDPContext *s = h->priv_data;
> >      int is_output;
> > @@ -708,7 +708,8 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> >              s->burst_bits = strtoll(buf, NULL, 10);
> >          }
> >          if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
> > -            av_strlcpy(localaddr, buf, sizeof(localaddr));
> > +            av_freep(&s->localaddr);
> > +            s->localaddr = av_strdup(buf);
> 
> Missing check.

If the localaddr is NULL, it'll not be used, so I haven't consider to add checked.
If you think it's better to consider this is error, I'll add it.

> 
> >          }
> >          if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
> >              if ((ret = ff_ip_parse_sources(h, buf, &s->filters)) < 0)
> > @@ -748,10 +749,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> >      if ((s->is_multicast || s->local_port <= 0) && (h->flags & AVIO_FLAG_READ))
> >          s->local_port = port;
> >  
> > -    if (localaddr[0])
> > -        udp_fd = udp_socket_create(h, &my_addr, &len, localaddr);
> > -    else
> > -        udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
> > +    udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
> >      if (udp_fd < 0)
> >          goto fail;
> >  
> > 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/udp.c b/libavformat/udp.c
index bbe5aec..b8b0e19 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -623,7 +623,7 @@  end:
 /* return non zero if error */
 static int udp_open(URLContext *h, const char *uri, int flags)
 {
-    char hostname[1024], localaddr[1024] = "";
+    char hostname[1024];
     int port, udp_fd = -1, tmp, bind_ret = -1, dscp = -1;
     UDPContext *s = h->priv_data;
     int is_output;
@@ -708,7 +708,8 @@  static int udp_open(URLContext *h, const char *uri, int flags)
             s->burst_bits = strtoll(buf, NULL, 10);
         }
         if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
-            av_strlcpy(localaddr, buf, sizeof(localaddr));
+            av_freep(&s->localaddr);
+            s->localaddr = av_strdup(buf);
         }
         if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
             if ((ret = ff_ip_parse_sources(h, buf, &s->filters)) < 0)
@@ -748,10 +749,7 @@  static int udp_open(URLContext *h, const char *uri, int flags)
     if ((s->is_multicast || s->local_port <= 0) && (h->flags & AVIO_FLAG_READ))
         s->local_port = port;
 
-    if (localaddr[0])
-        udp_fd = udp_socket_create(h, &my_addr, &len, localaddr);
-    else
-        udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
+    udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
     if (udp_fd < 0)
         goto fail;