[vlc-devel] [PATCH 3/3] posix: use strerror_r() if strerror_l() is unimplemented

Rémi Denis-Courmont remi at remlab.net
Sat Sep 12 20:03:10 CEST 2015


Le 2015-09-12 20:23, Sean McGovern a écrit :
> ---
>  src/posix/error.c |   26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
>
> diff --git a/src/posix/error.c b/src/posix/error.c
> index db51004..790e5bb 100644
> --- a/src/posix/error.c
> +++ b/src/posix/error.c
> @@ -29,6 +29,23 @@
>
>  #include <vlc_common.h>
>
> +#ifndef HAVE_STRERROR_L
> +static const char *vlc_strerror_r(int errnum)
> +{
> +#define BUF_LEN 256
> +    char *buf = malloc(BUF_LEN);
> +    if(unlikely(buf == NULL))
> +        return buf;
> +
> +    if(strerror_r(errnum, buf, BUF_LEN))
> +    {
> +        free(buf);
> +        buf = NULL;

This function is not allowed to return NULL. Call sites would crash.

> +    }
> +
> +    return buf;

Memory leak.

> +}
> +#else
>  static const char *vlc_strerror_l(int errnum, const char *lname)
>  {
>      int saved_errno = errno;
> @@ -53,6 +70,7 @@ static const char *vlc_strerror_l(int errnum, const
> char *lname)
>      freelocale(loc);
>      return buf;
>  }
> +#endif
>
>  /**
>   * Formats an error message in the current locale.
> @@ -63,7 +81,11 @@ static const char *vlc_strerror_l(int errnum,
> const char *lname)
>  const char *vlc_strerror(int errnum)
>  {
>      /* We cannot simply use strerror() here, since it is not 
> thread-safe. */
> +#ifndef HAVE_STRERROR_L
> +    return vlc_strerror_r(errnum);
> +#else
>      return vlc_strerror_l(errnum, "");
> +#endif
>  }
>
>  /**
> @@ -74,5 +96,9 @@ const char *vlc_strerror(int errnum)
>   */
>  const char *vlc_strerror_c(int errnum)
>  {
> +#ifndef HAVE_STRERROR_L
> +    return vlc_strerror_r(errnum);

This will cause translated error messages in the log. This might mean 
nothing to you. But *I* get to review a a lot of debug logs in locales I 
don't understand.

> +#else
>      return vlc_strerror_l(errnum, "C");
> +#endif
>  }

-- 
Rémi Denis-Courmont
http://www.remlab.net/


More information about the vlc-devel mailing list