From 81a1270a56bf1f6a13e709e653598c69c7d9334b Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 23 Jun 2015 16:23:25 +0200 Subject: fixed SEGFAULTs in InterfaceCurses::vmsg() * both vmsg() and stdio_msg() behave like vprintf() are allowed to leave their `va_list` in an undefined state. * therefore when writing messages to stdio in addition to the message line, we have to copy the argument list. * fixes SEGFAULTs when trying to log any message (but this bug did not manifest on every test system) --- src/interface-curses.cpp | 17 +++++++++-------- src/interface.cpp | 8 ++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/interface-curses.cpp b/src/interface-curses.cpp index e46af51..c3216ce 100644 --- a/src/interface-curses.cpp +++ b/src/interface-curses.cpp @@ -384,20 +384,21 @@ InterfaceCurses::vmsg_impl(MessageType type, const gchar *fmt, va_list ap) { attr_t attr; + if (!msg_window) { /* batch mode */ + stdio_vmsg(type, fmt, ap); + return; + } + /* * On most platforms we can write to stdout/stderr * even in interactive mode. */ #if defined(XCURSES) || defined(PDCURSES_WIN32A) || \ defined(NCURSES_UNIX) || defined(NCURSES_WIN32) - stdio_vmsg(type, fmt, ap); - if (!msg_window) /* batch mode */ - return; -#else - if (!msg_window) { /* batch mode */ - stdio_vmsg(type, fmt, ap); - return; - } + va_list aq; + va_copy(aq, ap); + stdio_vmsg(type, fmt, aq); + va_end(aq); #endif switch (type) { diff --git a/src/interface.cpp b/src/interface.cpp index 41cc93d..0bcdf28 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -107,6 +107,14 @@ Interface::UndoTokenInfoUpdate::run(void) interface.info_update(obj); } +/** + * Print a message to the appropriate stdio streams. + * + * This method has similar semantics to `vprintf`, i.e. + * it leaves `ap` undefined. Therefore to pass the format + * string and arguments to another `vprintf`-like function, + * you have to copy the arguments via `va_copy`. + */ template void Interface::stdio_vmsg(MessageType type, const gchar *fmt, va_list ap) -- cgit v1.2.3