diff options
author | Tom Tromey <tom@tromey.com> | 2023-06-18 22:06:05 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2023-06-20 07:52:28 -0600 |
commit | c65030964b684fd1df13346b678b42beee9af8e1 (patch) | |
tree | ea1ed63cb2b551fa158df61089c602bac3ca0ee0 /gdb | |
parent | 6b19f38ae331d2d889354fcd749e2478a868251c (diff) | |
download | binutils-c65030964b684fd1df13346b678b42beee9af8e1.zip binutils-c65030964b684fd1df13346b678b42beee9af8e1.tar.gz binutils-c65030964b684fd1df13346b678b42beee9af8e1.tar.bz2 |
Use std::string in do_set_command
do_set_command manually updates a string, only to copy it to a
std::string and free the working copy. This patch changes this code
to use std::string for everything, simplifying the code and removing a
copy.
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/cli/cli-setshow.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index ecb739b..c7bbac1 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -340,14 +340,12 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) { case var_string: { - char *newobj; + std::string newobj; const char *p; - char *q; int ch; - newobj = (char *) xmalloc (strlen (arg) + 2); + newobj.reserve (strlen (arg)); p = arg; - q = newobj; while ((ch = *p++) != '\000') { if (ch == '\\') @@ -365,20 +363,14 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) if (ch == 0) break; /* C loses */ else if (ch > 0) - *q++ = ch; + newobj.push_back (ch); } else - *q++ = ch; + newobj.push_back (ch); } -#if 0 - if (*(p - 1) != '\\') - *q++ = ' '; -#endif - *q++ = '\0'; - newobj = (char *) xrealloc (newobj, q - newobj); - - option_changed = c->var->set<std::string> (std::string (newobj)); - xfree (newobj); + newobj.shrink_to_fit (); + + option_changed = c->var->set<std::string> (std::move (newobj)); } break; case var_string_noescape: |