[FFmpeg-devel] [PATCH] Make cmdutils.c:print_error() use strerror() if av_strerror() fails (e.g. if strerror_r() is not defined)

Stefano Sabatini stefano.sabatini-lala
Tue May 4 15:41:46 CEST 2010


On date Tuesday 2010-05-04 04:53:39 +0200, Michael Niedermayer encoded:
> On Tue, May 04, 2010 at 12:03:33AM +0200, Stefano Sabatini wrote:
> > Hi, subject says it all.
> > 
> > This is meant to fix issue #1894.
> > 
> > Regards.
> > -- 
> > FFmpeg = Fiendish and Fundamentalist Mastodontic Philosophical Elitist Genius
> 
> >  error.c |    3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 218a948be301740f83d4e120453ae4a4c68728f2  0001-Make-av_strerror-return-1-even-in-the-case-when-av_s.patch
> > >From e1eeee18829336838ad5c05b9480d798bf3aeb96 Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > Date: Mon, 3 May 2010 23:28:01 +0200
> > Subject: [PATCH 1/3] Make av_strerror() return -1 even in the case when av_strerror_r() is
> >  not defined.
> > 
> > ---
> >  libavutil/error.c |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> > 
> > diff --git a/libavutil/error.c b/libavutil/error.c
> > index 3dd38a3..cb9a73c 100644
> > --- a/libavutil/error.c
> > +++ b/libavutil/error.c
> > @@ -34,10 +34,11 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
> >      if (errstr) {
> >          av_strlcpy(errbuf, errstr, errbuf_size);
> >      } else {
> > +        ret = -1;
> >  #if HAVE_STRERROR_R
> >          ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);
> >  #endif
> > -        if (!HAVE_STRERROR_R || ret < 0)
> > +        if (ret < 0)
> >              snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
> >      }
> 
> you mess up the return code

The idea is to issue -1 also in the case where HAVE_STRERROR_R is not
defined and that the error code is not recognized, this way the
calling function knows that a code description was not given.

Check if you prefer the new patch approach.

> 
> >  
> > -- 
> > 1.7.0
> > 
> 
> >  cmdutils.c |    6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > cb66fd1350d7bb6698b1ed175f66dcb8f7f4334f  0002-Make-print_error-use-strerror-in-case-av_strerror-fa.patch
> > >From 9050e3ac4a1c2aab6c413a71b484a4fa89281c3a Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > Date: Mon, 3 May 2010 23:36:21 +0200
> > Subject: [PATCH 2/3] Make print_error() use strerror() in case av_strerror() fails.
> > 
> > Should provide a meaningful error message for systems which do not
> > support strerror_r().
> > 
> > Fix roundup issue #1894.
> > ---
> >  cmdutils.c |    6 ++++--
> >  1 files changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/cmdutils.c b/cmdutils.c
> > index e6efc49..0de1d2d 100644
> > --- a/cmdutils.c
> > +++ b/cmdutils.c
> > @@ -300,8 +300,10 @@ void print_error(const char *filename, int err)
> >          break;
> >  #endif
> >      default:
> > -        av_strerror(err, errbuf, sizeof(errbuf));
> > -        fprintf(stderr, "%s: %s\n", filename, errbuf);
> > +        if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
> > +            fprintf(stderr, "%s: %s\n", filename, strerror(AVUNERROR(err)));
> > +        else
> > +            fprintf(stderr, "%s: %s\n", filename, errbuf);
> 
> missing {} and you should document the thread saftey issues tis introduces
> users of the code likely want to know

Uhm it's a cmdutils.c function, I don't think we need to document
this. Note also that the usage in ffplay of print_error() looks safe
anyway, since print_error() is used only in the init phase, with just
one active thread.

> besides
> errbuf= strerror(AVUNERROR(err)
> should simplify this

Regards.
-- 
FFmpeg = Fierce and Fantastic Maxi Powerful Exuberant Governor



More information about the ffmpeg-devel mailing list