From: Simon Marchi Date: Thu, 8 Mar 2018 23:04:07 +0000 (-0500) Subject: linux_qxfer_libraries_svr4: Use std::string X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f6e8a41e6724e641d3b831983e4d158ff069b8ed;p=binutils-gdb.git linux_qxfer_libraries_svr4: Use std::string Use std::string, removing some manual memory management. gdb/gdbserver/ChangeLog: * linux-low.c (linux_qxfer_libraries_svr4): Use std::string. --- diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index f7de928d18c..33c0484de6e 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,7 @@ +2018-03-08 Simon Marchi + + * linux-low.c (linux_qxfer_libraries_svr4): Use std::string. + 2018-03-02 Simon Marchi * server.c (handle_general_set): Remove unnecessary xstrdup. diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 00385ce4c91..c8bb1f5785d 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -6988,8 +6988,6 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, unsigned const char *writebuf, CORE_ADDR offset, int len) { - char *document; - unsigned document_len; struct process_info_private *const priv = current_process ()->priv; char filename[PATH_MAX]; int pid, is_elf64; @@ -7019,8 +7017,6 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, unsigned int machine; int ptr_size; CORE_ADDR lm_addr = 0, lm_prev = 0; - int allocated = 1024; - char *p; CORE_ADDR l_name, l_addr, l_ld, l_next, l_prev; int header_done = 0; @@ -7093,9 +7089,7 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, } } - document = (char *) xmalloc (allocated); - strcpy (document, "l_name_offset, @@ -7125,10 +7119,7 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, executable does not have PT_DYNAMIC present and this function already exited above due to failed get_r_debug. */ if (lm_prev == 0) - { - sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr); - p = p + strlen (p); - } + string_appendf (document, " main-lm=\"0x%lx\"", (unsigned long) lm_addr); else { /* Not checking for error because reading may stop before @@ -7138,31 +7129,19 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, libname[sizeof (libname) - 1] = '\0'; if (libname[0] != '\0') { - /* 6x the size for xml_escape_text below. */ - size_t len = 6 * strlen ((char *) libname); - if (!header_done) { /* Terminate `", - name.c_str (), (unsigned long) lm_addr, - (unsigned long) l_addr, (unsigned long) l_ld); + string_appendf (document, + "", + name.c_str (), (unsigned long) lm_addr, + (unsigned long) l_addr, (unsigned long) l_ld); } } @@ -7173,12 +7152,12 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, if (!header_done) { /* Empty list; terminate `"); + document += "/>"; } else - strcpy (p, ""); + document += ""; - document_len = strlen (document); + int document_len = document.length (); if (offset < document_len) document_len -= offset; else @@ -7186,8 +7165,7 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, if (len > document_len) len = document_len; - memcpy (readbuf, document + offset, len); - xfree (document); + memcpy (readbuf, document.data () + offset, len); return len; }