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

Michael Niedermayer michaelni
Tue May 4 04:53:39 CEST 2010


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

>  
> -- 
> 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
besides
errbuf= strerror(AVUNERROR(err)
should simplify this


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100504/4b5aa71e/attachment.pgp>



More information about the ffmpeg-devel mailing list