This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] PR tui/14159 TUI segfault on quit
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 24 May 2012 16:56:46 +0100
- Subject: [PATCH] PR tui/14159 TUI segfault on quit
We're reusing a va_list over several printf-like calls, which is not
valid C. Fix it in the same way defaulted_query fixes it.
Applied.
2012-05-24 Pedro Alves <palves@redhat.com>
PR tui/14159
* tui/tui-hooks.c (tui_query_hook): Pre-compute the question
string, instead of reusing the va_list argument.
---
gdb/tui/tui-hooks.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index 17a9593..4d1e063 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -69,6 +69,13 @@ tui_query_hook (const char *msg, va_list argp)
int retval;
int ans2;
int answer;
+ char *question;
+ struct cleanup *old_chain;
+
+ /* Format the question outside of the loop, to avoid reusing
+ ARGP. */
+ question = xstrvprintf (msg, argp);
+ old_chain = make_cleanup (xfree, question);
echo ();
while (1)
@@ -76,7 +83,7 @@ tui_query_hook (const char *msg, va_list argp)
wrap_here (""); /* Flush any buffered output. */
gdb_flush (gdb_stdout);
- vfprintf_filtered (gdb_stdout, msg, argp);
+ fputs_filtered (question, gdb_stdout);
printf_filtered (_("(y or n) "));
wrap_here ("");
@@ -113,6 +120,8 @@ tui_query_hook (const char *msg, va_list argp)
printf_filtered (_("Please answer y or n.\n"));
}
noecho ();
+
+ do_cleanups (old_chain);
return retval;
}