From b7b030adc405017f01e996a90f85e40730ef8397 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 12 Oct 2017 16:48:35 -0600 Subject: Return unique_xmalloc_ptr from target_read_stralloc This changes target_read_stralloc to return a unique_xmalloc_ptr, and then fixes all the callers. unique_xmalloc_ptr is used, rather than std::string, because target_read_stralloc gives a special meaning to a NULL return. ChangeLog 2017-10-16 Tom Tromey * xml-syscall.c (xml_init_syscalls_info): Update. * xml-support.c (xinclude_start_include): Update. (xml_fetch_content_from_file): Return unique_xmalloc_ptr. * xml-support.h (xml_fetch_another): Return unique_xmalloc_ptr. (xml_fetch_content_from_file): Likewise. * osdata.c (get_osdata): Update. * target.h (target_read_stralloc, target_get_osdata): Return unique_xmalloc_ptr. * solib-aix.c (solib_aix_get_library_list): Update. * solib-target.c (solib_target_current_sos): Update. * solib-svr4.c (svr4_current_sos_via_xfer_libraries): Update. * xml-tdesc.c (fetch_available_features_from_target): Update. (target_fetch_description_xml): Update. (file_read_description_xml): Update. * remote.c (remote_get_threads_with_qxfer, remote_memory_map) (remote_traceframe_info, btrace_read_config, remote_read_btrace) (remote_pid_to_exec_file): Update. * target.c (target_read_stralloc): Return unique_xmalloc_ptr. (target_get_osdata): Likewise. --- gdb/target.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'gdb/target.c') diff --git a/gdb/target.c b/gdb/target.c index 4a7589d..94307cb 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1924,13 +1924,9 @@ target_read_alloc (struct target_ops *ops, enum target_object object, return target_read_alloc_1 (ops, object, annex, buf_p, 0); } -/* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and - returned as a string, allocated using xmalloc. If an error occurs - or the transfer is unsupported, NULL is returned. Empty objects - are returned as allocated but empty strings. A warning is issued - if the result contains any embedded NUL bytes. */ +/* See target.h. */ -char * +gdb::unique_xmalloc_ptr target_read_stralloc (struct target_ops *ops, enum target_object object, const char *annex) { @@ -1945,7 +1941,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object, return NULL; if (transferred == 0) - return xstrdup (""); + return gdb::unique_xmalloc_ptr (xstrdup ("")); bufstr[transferred] = 0; @@ -1959,7 +1955,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object, break; } - return bufstr; + return gdb::unique_xmalloc_ptr (bufstr); } /* Memory transfer methods. */ @@ -2654,7 +2650,9 @@ target_supports_multi_process (void) return (*current_target.to_supports_multi_process) (¤t_target); } -char * +/* See target.h. */ + +gdb::unique_xmalloc_ptr target_get_osdata (const char *type) { struct target_ops *t; -- cgit v1.1