[FFmpeg-devel] [PATCH v4 2/3] avformat/network: Return 0/AVERROR from ff_network_init()
Andrew Sayers
ffmpeg-devel at pileofstuff.org
Tue May 7 16:12:51 EEST 2024
On Sun, May 05, 2024 at 10:05:36PM +0200, Marton Balint wrote:
>
>
> On Sat, 20 Apr 2024, Andrew Sayers wrote:
>
> > ---
> > libavformat/avio.c | 4 ++--
> > libavformat/network.c | 7 +++----
> > libavformat/rtsp.c | 12 ++++++------
> > libavformat/rtspdec.c | 4 ++--
> > libavformat/sapdec.c | 4 ++--
> > libavformat/sapenc.c | 4 ++--
> > 6 files changed, 17 insertions(+), 18 deletions(-)
> >
> > diff --git a/libavformat/avio.c b/libavformat/avio.c
> > index d109f3adff..f82edec779 100644
> > --- a/libavformat/avio.c
> > +++ b/libavformat/avio.c
> > @@ -123,8 +123,8 @@ static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up,
> > int err;
> >
> > #if CONFIG_NETWORK
> > - if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init())
> > - return AVERROR(EIO);
> > + if (up->flags & URL_PROTOCOL_FLAG_NETWORK && (err=ff_network_init())<0)
> > + return err;
> > #endif
> > if ((flags & AVIO_FLAG_READ) && !up->url_read) {
> > av_log(NULL, AV_LOG_ERROR,
> > diff --git a/libavformat/network.c b/libavformat/network.c
> > index f295957aa5..c1b0e69362 100644
> > --- a/libavformat/network.c
> > +++ b/libavformat/network.c
> > @@ -59,11 +59,10 @@ int ff_network_init(void)
> > {
> > #if HAVE_WINSOCK2_H
> > WSADATA wsaData;
> > -
> > - if (WSAStartup(MAKEWORD(1,1), &wsaData))
> > - return 0;
> > + return ff_neterrno2(WSAStartup(MAKEWORD(1,1), &wsaData));
> > +#else
> > + return 0;
> > #endif
> > - return 1;
> > }
> >
> > int ff_network_wait_fd(int fd, int write)
> > diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> > index b0c61ee00a..3db4ed11c2 100644
> > --- a/libavformat/rtsp.c
> > +++ b/libavformat/rtsp.c
> > @@ -1740,8 +1740,8 @@ int ff_rtsp_connect(AVFormatContext *s)
> > return AVERROR(EINVAL);
> > }
> >
> > - if (!ff_network_init())
> > - return AVERROR(EIO);
> > + if ((err = ff_network_init())<0)
> > + return err;
>
> Assignments in if conditions should be avoided. So this should be expanded
> to:
>
> err = ff_network_init();
> if (err < 0)
> return err;
>
> Same for the rest of the checks later.
>
> Thanks,
> Marton
Assignments in if conditions seem to be the standard in that file, so I figured
it was better to have one ugly standard than two competing ones. But I agree
they're not good, so I'll propose a new patch in a few days if nobody objects.
More information about the ffmpeg-devel
mailing list