This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Use std::string in do_set_command
- From: Tom Tromey <tromey at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 3 Sep 2017 19:04:09 -0000
- Subject: [binutils-gdb] Use std::string in do_set_command
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b57af50345945f32e6615391ac62a4f589c0fada
commit b57af50345945f32e6615391ac62a4f589c0fada
Author: Tom Tromey <tom@tromey.com>
Date: Sun Aug 13 14:45:17 2017 -0600
Use std::string in do_set_command
Change do_set_command to use std::string, removing a cleanup and some
manual resizing code.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* cli/cli-setshow.c (do_set_command): Use std::string.
Diff:
---
gdb/ChangeLog | 4 ++++
gdb/cli/cli-setshow.c | 16 ++++------------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6d6dad1..ba1397f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
2017-09-03 Tom Tromey <tom@tromey.com>
+ * cli/cli-setshow.c (do_set_command): Use std::string.
+
+2017-09-03 Tom Tromey <tom@tromey.com>
+
* cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr.
2017-09-03 Tom Tromey <tom@tromey.com>
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index fb0bd49..c6e5ebc 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -367,24 +367,16 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
message. */
if (arg == NULL)
{
- char *msg;
- int msg_len = 0;
-
- for (i = 0; c->enums[i]; i++)
- msg_len += strlen (c->enums[i]) + 2;
-
- msg = (char *) xmalloc (msg_len);
- *msg = '\0';
- make_cleanup (xfree, msg);
+ std::string msg;
for (i = 0; c->enums[i]; i++)
{
if (i != 0)
- strcat (msg, ", ");
- strcat (msg, c->enums[i]);
+ msg += ", ";
+ msg += c->enums[i];
}
error (_("Requires an argument. Valid arguments are %s."),
- msg);
+ msg.c_str ());
}
p = strchr (arg, ' ');