[gpm] [PATCH] Avoid reusing of va_list
Tomas Janousek
tjanouse@redhat.com
Wed Jul 25 11:42:11 CEST 2007
This fixes https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=246219
(gpm uses variable argument lists incorrectly)
Signed-off-by: Tomas Janousek <tjanouse@redhat.com>
---
src/report.c | 33 +++++++++++++++++++++++----------
1 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/src/report.c b/src/report.c
index 975c9a3..e4777e0 100644
--- a/src/report.c
+++ b/src/report.c
@@ -72,9 +72,16 @@
void gpm_report(int line, char *file, int stat, char *text, ... )
{
FILE *f = NULL;
- va_list ap;
+ va_list ap, ap3;
+#ifdef HAVE_VSYSLOG
+ va_list ap2;
+#endif
va_start(ap,text);
+ va_copy(ap3, ap);
+#ifdef HAVE_VSYSLOG
+ va_copy(ap2, ap);
+#endif
switch(option.run_status) {
/******************** STARTUP *****************/
@@ -84,7 +91,7 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
case GPM_STAT_INFO:
#ifdef HAVE_VSYSLOG
syslog(LOG_INFO | LOG_USER, GPM_STRING_INFO);
- vsyslog(LOG_INFO | LOG_USER, text, ap);
+ vsyslog(LOG_INFO | LOG_USER, text, ap2);
#endif
fprintf(stderr,GPM_STRING_INFO);
vfprintf(stderr,text,ap);
@@ -94,7 +101,7 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
case GPM_STAT_WARN:
#ifdef HAVE_VSYSLOG
syslog(LOG_DAEMON | LOG_WARNING, GPM_STRING_WARN);
- vsyslog(LOG_DAEMON | LOG_WARNING, text, ap);
+ vsyslog(LOG_DAEMON | LOG_WARNING, text, ap2);
#endif
fprintf(stderr,GPM_STRING_WARN);
vfprintf(stderr,text,ap);
@@ -104,7 +111,7 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
case GPM_STAT_ERR:
#ifdef HAVE_VSYSLOG
syslog(LOG_DAEMON | LOG_ERR, GPM_STRING_ERR);
- vsyslog(LOG_DAEMON | LOG_ERR, text, ap);
+ vsyslog(LOG_DAEMON | LOG_ERR, text, ap2);
#endif
fprintf(stderr,GPM_STRING_ERR);
vfprintf(stderr,text,ap);
@@ -114,7 +121,7 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
case GPM_STAT_OOPS:
#ifdef HAVE_VSYSLOG
syslog(LOG_DAEMON | LOG_ERR, GPM_STRING_OOPS);
- vsyslog(LOG_DAEMON | LOG_ERR, text, ap);
+ vsyslog(LOG_DAEMON | LOG_ERR, text, ap2);
#endif
fprintf(stderr,GPM_STRING_OOPS);
vfprintf(stderr,text,ap);
@@ -131,14 +138,14 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
case GPM_STAT_INFO:
#ifdef HAVE_VSYSLOG
syslog(LOG_INFO | LOG_USER, GPM_STRING_INFO);
- vsyslog(LOG_INFO | LOG_USER, text, ap);
+ vsyslog(LOG_INFO | LOG_USER, text, ap2);
#endif
break;
case GPM_STAT_WARN:
#ifdef HAVE_VSYSLOG
syslog(LOG_DAEMON | LOG_WARNING, GPM_STRING_WARN);
- vsyslog(LOG_DAEMON | LOG_WARNING, text, ap);
+ vsyslog(LOG_DAEMON | LOG_WARNING, text, ap2);
#endif
if ((f = fopen(GPM_SYS_CONSOLE, "a")) != NULL) {
fprintf(f, GPM_STRING_WARN);
@@ -151,7 +158,7 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
case GPM_STAT_ERR:
#ifdef HAVE_VSYSLOG
syslog(LOG_DAEMON | LOG_ERR, GPM_STRING_ERR);
- vsyslog(LOG_DAEMON | LOG_ERR, text, ap);
+ vsyslog(LOG_DAEMON | LOG_ERR, text, ap2);
#endif
if ((f = fopen(GPM_SYS_CONSOLE, "a")) != NULL) {
fprintf(f, GPM_STRING_ERR);
@@ -162,7 +169,7 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
if ((f = fopen(console.device, "a")) != NULL) {
fprintf(f, GPM_STRING_ERR);
- vfprintf(f, text, ap);
+ vfprintf(f, text, ap3);
fprintf(f, "\n");
fclose(f);
}
@@ -171,7 +178,7 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
case GPM_STAT_OOPS:
#ifdef HAVE_VSYSLOG
syslog(LOG_DAEMON | LOG_ERR, GPM_STRING_OOPS);
- vsyslog(LOG_DAEMON | LOG_ERR, text, ap);
+ vsyslog(LOG_DAEMON | LOG_ERR, text, ap2);
#endif
fprintf(stderr,GPM_STRING_OOPS);
vfprintf(stderr,text,ap);
@@ -209,6 +216,12 @@ void gpm_report(int line, char *file, int stat, char *text, ... )
break;
} /* switch for current modus */
+
+ va_end(ap);
+ va_end(ap3);
+#ifdef HAVE_VSYSLOG
+ va_end(ap2);
+#endif
} /* gpm_report */
--
1.5.2.2
--
Tomas Janousek, SW Engineer, Red Hat, Inc.
More information about the gpm
mailing list