diff options
author | Tom Tromey <tom@tromey.com> | 2018-08-29 23:03:09 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-13 16:22:34 -0600 |
commit | 803c08d083556154cd4d27368e58b359e9de8b93 (patch) | |
tree | 900369c589d11a5926ca59fe244987389692a526 /gdb/utils.c | |
parent | 5b4cbbe357aaf6462a68e1a15c9532dd3d01e06d (diff) | |
download | gdb-803c08d083556154cd4d27368e58b359e9de8b93.zip gdb-803c08d083556154cd4d27368e58b359e9de8b93.tar.gz gdb-803c08d083556154cd4d27368e58b359e9de8b93.tar.bz2 |
Return std::string from gdb_bfd_errmsg
This changes gdb_bfd_errmsg to return a std::string, removing a
cleanup. This approach may be slightly less efficient than the
previous code, but I don't believe this is very important in this
situation.
gdb/ChangeLog
2018-09-13 Tom Tromey <tom@tromey.com>
* utils.h (gdb_bfd_errmsg): Return std::string.
* exec.c (exec_file_attach): Update.
* compile/compile-object-load.c (compile_object_load): Update.
* utils.c (gdb_bfd_errmsg): Return std::string.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 7a8c80c..d7980fe 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2921,39 +2921,26 @@ compare_positive_ints (const void *ap, const void *bp) #define AMBIGUOUS_MESS2 \ ".\nUse \"set gnutarget format-name\" to specify the format." -const char * +std::string gdb_bfd_errmsg (bfd_error_type error_tag, char **matching) { - char *ret, *retp; - int ret_len; char **p; /* Check if errmsg just need simple return. */ if (error_tag != bfd_error_file_ambiguously_recognized || matching == NULL) return bfd_errmsg (error_tag); - ret_len = strlen (bfd_errmsg (error_tag)) + strlen (AMBIGUOUS_MESS1) - + strlen (AMBIGUOUS_MESS2); - for (p = matching; *p; p++) - ret_len += strlen (*p) + 1; - ret = (char *) xmalloc (ret_len + 1); - retp = ret; - make_cleanup (xfree, ret); - - strcpy (retp, bfd_errmsg (error_tag)); - retp += strlen (retp); - - strcpy (retp, AMBIGUOUS_MESS1); - retp += strlen (retp); + std::string ret (bfd_errmsg (error_tag)); + ret += AMBIGUOUS_MESS1; for (p = matching; *p; p++) { - sprintf (retp, " %s", *p); - retp += strlen (retp); + ret += " "; + ret += *p; } - xfree (matching); + ret += AMBIGUOUS_MESS2; - strcpy (retp, AMBIGUOUS_MESS2); + xfree (matching); return ret; } |