[RFA,08/12] Remove cleanup from complaints.c

Message ID 20170928195011.27382-9-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 28, 2017, 7:50 p.m. UTC
  This removes a cleanup from complaints.c by using std::string.

gdb/ChangeLog
2017-09-28  Tom Tromey  <tom@tromey.com>

	* complaints.c (vcomplaint): Use std::string.
---
 gdb/ChangeLog    | 4 ++++
 gdb/complaints.c | 9 +++------
 2 files changed, 7 insertions(+), 6 deletions(-)
  

Comments

Pedro Alves Sept. 28, 2017, 10:09 p.m. UTC | #1
On 09/28/2017 08:50 PM, Tom Tromey wrote:

> -	  char *msg;
> -	  struct cleanup *cleanups;
> -	  msg = xstrvprintf (fmt, args);
> -	  cleanups = make_cleanup (xfree, msg);
> +	  std::string msg (string_vprintf (fmt, args));

Please use copy-init.  Otherwise OK.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/complaints.c b/gdb/complaints.c
index aba305c..6456cae 100644
--- a/gdb/complaints.c
+++ b/gdb/complaints.c
@@ -192,16 +192,14 @@  vcomplaint (struct complaints **c, const char *file,
 	vwarning (fmt, args);
       else
 	{
-	  char *msg;
-	  struct cleanup *cleanups;
-	  msg = xstrvprintf (fmt, args);
-	  cleanups = make_cleanup (xfree, msg);
+	  std::string msg (string_vprintf (fmt, args));
 	  wrap_here ("");
 	  if (series != SUBSEQUENT_MESSAGE)
 	    begin_line ();
 	  /* XXX: i18n */
 	  fprintf_filtered (gdb_stderr, "%s%s%s",
-			    complaints->explanation[series].prefix, msg,
+			    complaints->explanation[series].prefix,
+			    msg.c_str (),
 			    complaints->explanation[series].postfix);
 	  /* Force a line-break after any isolated message.  For the
              other cases, clear_complaints() takes care of any missing
@@ -214,7 +212,6 @@  vcomplaint (struct complaints **c, const char *file,
 	    fputs_filtered ("\n", gdb_stderr);
 	  else
 	    wrap_here ("");
-	  do_cleanups (cleanups);
 	}
     }