[libdvbpsi-devel] [PATCH 2/6] dvbpsi: fix when _GNU_SOURCE is not defined
Timothy Gu
timothygu99 at gmail.com
Fri Jun 27 01:15:16 CEST 2014
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
More information about the libdvbpsi-devel
mailing list