From 91bfa780ddd229cff6c3d86a8f05e3898ef65e53 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Fri, 26 Feb 2010 09:32:15 +0000 Subject: [PATCH] Fix crash when using printf format specifiers in traceEvent (#3874) --- rts/Trace.c | 14 +++++++++++--- rts/eventlog/EventLog.c | 4 ++-- rts/eventlog/EventLog.h | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/rts/Trace.c b/rts/Trace.c index a1da991..c8a0285 100644 --- a/rts/Trace.c +++ b/rts/Trace.c @@ -299,21 +299,29 @@ void trace_(char *msg, ...) va_end(ap); } -void traceUserMsg(Capability *cap, char *msg) +static void traceFormatUserMsg(Capability *cap, char *msg, ...) { + va_list ap; + va_start(ap,msg); + #ifdef DEBUG if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { - traceCap_stderr(cap, msg, NULL); + traceCap_stderr(cap, msg, ap); } else #endif { if (eventlog_enabled) { - postUserMsg(cap, msg); + postUserMsg(cap, msg, ap); } } dtraceUserMsg(cap->no, msg); } +void traceUserMsg(Capability *cap, char *msg) +{ + traceFormatUserMsg(cap, "%s", msg); +} + void traceThreadStatus_ (StgTSO *tso USED_IF_DEBUG) { #ifdef DEBUG diff --git a/rts/eventlog/EventLog.c b/rts/eventlog/EventLog.c index ede1615..7026a2a 100644 --- a/rts/eventlog/EventLog.c +++ b/rts/eventlog/EventLog.c @@ -448,9 +448,9 @@ void postCapMsg(Capability *cap, char *msg, va_list ap) postLogMsg(&capEventBuf[cap->no], EVENT_LOG_MSG, msg, ap); } -void postUserMsg(Capability *cap, char *msg) +void postUserMsg(Capability *cap, char *msg, va_list ap) { - postLogMsg(&capEventBuf[cap->no], EVENT_USER_MSG, msg, NULL); + postLogMsg(&capEventBuf[cap->no], EVENT_USER_MSG, msg, ap); } void closeBlockMarker (EventsBuf *ebuf) diff --git a/rts/eventlog/EventLog.h b/rts/eventlog/EventLog.h index e2b8043..fd87820 100644 --- a/rts/eventlog/EventLog.h +++ b/rts/eventlog/EventLog.h @@ -39,7 +39,7 @@ void postEvent(Capability *cap, EventTypeNum tag); void postMsg(char *msg, va_list ap); -void postUserMsg(Capability *cap, char *msg); +void postUserMsg(Capability *cap, char *msg, va_list ap); void postCapMsg(Capability *cap, char *msg, va_list ap); -- 1.7.10.4