[libdvbpsi-devel] [PATCH 2/6] dvbpsi: fix when _GNU_SOURCE is not defined

Jean-Paul Saman jpsaman at videolan.org
Mon Sep 8 14:44:57 CEST 2014


Patch rewritten and merged in http://git.m2x.eu/videolan/libdvbpsi.git,
it will show up in git.videolan.org/libdvbpsi.git later on.


Kind regards,
Jean-Paul Saman

On Fri, Jun 27, 2014 at 1:15 AM, Timothy Gu <timothygu99 at gmail.com> wrote:

> Based on a patch by Guilherme Lima Bernal <lb-guilherme at live.com>.
>
> Signed-off-by: Timothy Gu <timothygu99 at gmail.com>
> ---
>  src/dvbpsi.c | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/src/dvbpsi.c b/src/dvbpsi.c
> index 89d4932..141e3df 100644
> --- a/src/dvbpsi.c
> +++ b/src/dvbpsi.c
> @@ -529,14 +529,10 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const
> dvbpsi_msg_level_t level, const char
>          msg = malloc(DVBPSI_MSG_SIZE);
>          if (msg == NULL) {
>              va_end(ap);
> -            return;
> -        }
> -        if (snprintf(&msg, DVBPSI_MSG_SIZE, DVBPSI_MSG_FORMAT, ap) < 0) {
> -            va_end(ap);
>              free(msg);
>              return;
>          }
> -        int err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap);
> +        int err = vsnprintf(msg, DVBPSI_MSG_SIZE, fmt, ap);
>  #endif
>          va_end(ap);
>          if (err > DVBPSI_MSG_NONE) {
> @@ -575,20 +571,28 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const
> dvbpsi_msg_level_t level, const char
>          free(msg);                                              \
>      } while(0);
>  #   else
> -#       define DVBPSI_MSG_COMMON                                \
> +#       define DVBPSI_MSG_COMMON(level)                         \
>      do {                                                        \
>          va_list ap;                                             \
>          va_start(ap, fmt);                                      \
>          char *msg = malloc(DVBPSI_MSG_SIZE);                    \
> -        if (msg == NULL) {                                      \
> +        char *tmp = malloc(DVBPSI_MSG_SIZE);                    \
> +        if (msg == NULL || tmp == NULL) {                       \
>              va_end(ap);                                         \
> +            if (msg)                                            \
> +                free(msg);                                      \
> +            if (tmp)                                            \
> +                free(tmp);                                      \
>              return;                                             \
>          }                                                       \
> -        if (snprintf(&msg, DVBPSI_MSG_SIZE, DVBPSI_MSG_FORMAT, src) < 0)
> { \
> +        if (vsnprintf(tmp, DVBPSI_MSG_SIZE, fmt, ap) < 0) {     \
>              va_end(ap);                                         \
> +            free(tmp);                                          \
> +            free(msg);                                          \
>              return;                                             \
>          }                                                       \
> -        int err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap);    \
> +        int err = snprintf(msg, DVBPSI_MSG_SIZE, DVBPSI_MSG_FORMAT, src,
> tmp); \
> +        free(tmp);                                              \
>          va_end(ap);                                             \
>          if (err > 0) {                                          \
>              if (dvbpsi->pf_message)                             \
> --
> 1.9.1
>
> _______________________________________________
> libdvbpsi-devel mailing list
> libdvbpsi-devel at videolan.org
> https://mailman.videolan.org/listinfo/libdvbpsi-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/libdvbpsi-devel/attachments/20140908/19118c04/attachment-0001.html>


More information about the libdvbpsi-devel mailing list