1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
This file is part of MXE.
See index.html for further information.
Submitted to upstream at
https://mailman.videolan.org/pipermail/libdvbpsi-devel/2014-June/000738.html
https://mailman.videolan.org/pipermail/libdvbpsi-devel/2014-June/000739.html
From ada90a3c9a5e8b1c8d214f9e9e82499b54060419 Mon Sep 17 00:00:00 2001
From: Timothy Gu <timothygu99@gmail.com>
Date: Tue, 24 Jun 2014 14:57:31 -0700
Subject: [PATCH 2/3] dvbpsi: fix when _GNU_SOURCE is not defined
Based on a patch by Guilherme Lima Bernal <lb-guilherme@live.com>.
Signed-off-by: Timothy Gu <timothygu99@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
From a2117900002bc8f9e0f821d872f8cd70ece67634 Mon Sep 17 00:00:00 2001
From: Timothy Gu <timothygu99@gmail.com>
Date: Thu, 26 Jun 2014 13:41:02 -0700
Subject: [PATCH 3/3] Add a separate check for [v]asprintf() instead of
checking for _GNU_SOURCE
Platforms like i686-pc-mingw32 defines _GNU_SOURCE but does not contain
the functions.
Signed-off-by: Timothy Gu <timothygu99@gmail.com>
---
configure.ac | 21 +++++++++++++++++++++
src/dvbpsi.c | 6 +++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 2a97e5b..f95c186 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,6 +100,27 @@ if test "${ac_cv_cpp_variadic_macros}" != "no"; then
AC_DEFINE(HAVE_VARIADIC_MACROS, 1, Support for variadic macros)
fi
+dnl Check for asprintf(). Systems with asprintf() must also have vasprintf(),
+dnl so it is not checked separately.
+AC_CACHE_CHECK([for asprintf()],
+ [ac_cv_asprintf],
+ [AC_COMPILE_IFELSE([
+ AC_LANG_SOURCE([[
+ #include <stdio.h>
+ #include <stdlib.h>
+ int main(void) {
+ char *text = NULL;
+ int ret = asprintf(&text, "test");
+ if (ret >= 0) free(text);
+ return 0;
+ }
+ ]])],
+ ac_cv_asprintf=yes,
+ ac_cv_asprintf=no)])
+if test "${ac_cv_asprintf}" != "no"; then
+ AC_DEFINE(HAVE_ASPRINTF, 1, [Support for asprintf() and vasprintf()])
+fi
+
dnl
dnl Generate Makefiles and other output files
dnl
diff --git a/src/dvbpsi.c b/src/dvbpsi.c
index 141e3df..29ae2b0 100644
--- a/src/dvbpsi.c
+++ b/src/dvbpsi.c
@@ -508,7 +508,7 @@ bool dvbpsi_packet_push(dvbpsi_t *p_dvbpsi, uint8_t* p_data)
* 1 is warning and errors
* 2 is debug, warning and errors
*****************************************************************************/
-#if !defined(_GNU_SOURCE)
+#if !defined(HAVE_ASPRINTF)
# define DVBPSI_MSG_SIZE 1024
#endif
@@ -523,7 +523,7 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
va_list ap;
va_start(ap, fmt);
char *msg = NULL;
-#if defined(_GNU_SOURCE)
+#if defined(HAVE_ASPRINTF)
int err = vasprintf(&msg, fmt, ap);
#else
msg = malloc(DVBPSI_MSG_SIZE);
@@ -545,7 +545,7 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
#else
/* Common code for printing messages */
-# if defined(_GNU_SOURCE)
+# if defined(HAVE_ASPRINTF)
# define DVBPSI_MSG_COMMON(level) \
do { \
va_list ap; \
--
1.9.1
|