+2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
+
+ * common/buffer.c (buffer_xml_printf): Adjust.
+ * common/xml-utils.c (xml_escape_text): Change return type to
+ std::string, update code accordingly.
+ * common/xml-utils.h (xml_escape_text): Change return type to
+ std::string.
+ * rs6000-aix-tdep.c (rs6000_aix_shared_library_to_xml): Adjust.
+ * windows-tdep.c (windows_xfer_shared_library): Adjust.
+ * unittests/xml-utils-selftests.c (test_xml_escape_text):
+ Adjust.
+
2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add new source file.
if (percent)
{
char buf[32];
- char *p;
char *str = buf;
const char *f_old = f;
if (str)
{
buffer_grow (buffer, prev, f_old - prev - 1);
- p = xml_escape_text (str);
- buffer_grow_str (buffer, p);
- xfree (p);
+ std::string p = xml_escape_text (str);
+ buffer_grow_str (buffer, p.c_str ());
prev = f + 1;
}
percent = 0;
#include "common-defs.h"
#include "xml-utils.h"
-/* Return a malloc allocated string with special characters from TEXT
- replaced by entity references. */
+/* Return a string with special characters from TEXT replaced by entity
+ references. */
-char *
+std::string
xml_escape_text (const char *text)
{
- char *result;
- int i, special;
-
- /* Compute the length of the result. */
- for (i = 0, special = 0; text[i] != '\0'; i++)
- switch (text[i])
- {
- case '\'':
- case '\"':
- special += 5;
- break;
- case '&':
- special += 4;
- break;
- case '<':
- case '>':
- special += 3;
- break;
- default:
- break;
- }
+ std::string result;
/* Expand the result. */
- result = (char *) xmalloc (i + special + 1);
- for (i = 0, special = 0; text[i] != '\0'; i++)
+ for (int i = 0; text[i] != '\0'; i++)
switch (text[i])
{
case '\'':
- strcpy (result + i + special, "'");
- special += 5;
+ result += "'";
break;
case '\"':
- strcpy (result + i + special, """);
- special += 5;
+ result += """;
break;
case '&':
- strcpy (result + i + special, "&");
- special += 4;
+ result += "&";
break;
case '<':
- strcpy (result + i + special, "<");
- special += 3;
+ result += "<";
break;
case '>':
- strcpy (result + i + special, ">");
- special += 3;
+ result += ">";
break;
default:
- result[i + special] = text[i];
+ result += text[i];
break;
}
- result[i + special] = '\0';
return result;
}
/* Return a malloc allocated string with special characters from TEXT
replaced by entity references. */
-extern char *xml_escape_text (const char *text);
+extern std::string xml_escape_text (const char *text);
#endif
+2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
+
+ * linux-low.c (linux_qxfer_libraries_svr4): Adjust to change of
+ return type of xml_escape_text.
+ * server.c (emit_dll_description): Likewise.
+
2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
* server.c (captured_main): Accept argument for --selftest.
{
/* 6x the size for xml_escape_text below. */
size_t len = 6 * strlen ((char *) libname);
- char *name;
if (!header_done)
{
p = document + document_len;
}
- name = xml_escape_text ((char *) libname);
+ std::string name = xml_escape_text ((char *) libname);
p += sprintf (p, "<library name=\"%s\" lm=\"0x%lx\" "
"l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>",
- name, (unsigned long) lm_addr,
+ name.c_str (), (unsigned long) lm_addr,
(unsigned long) l_addr, (unsigned long) l_ld);
- free (name);
}
}
struct dll_info *dll = (struct dll_info *) inf;
char **p_ptr = (char **) arg;
char *p = *p_ptr;
- char *name;
strcpy (p, " <library name=\"");
p = p + strlen (p);
- name = xml_escape_text (dll->name);
- strcpy (p, name);
- free (name);
+ std::string name = xml_escape_text (dll->name);
+ strcpy (p, name.c_str ());
p = p + strlen (p);
strcpy (p, "\"><segment address=\"");
p = p + strlen (p);
rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
struct obstack *obstack)
{
- char *p;
-
obstack_grow_str (obstack, "<library name=\"");
- p = xml_escape_text (ldi->filename);
- obstack_grow_str (obstack, p);
- xfree (p);
+ std::string p = xml_escape_text (ldi->filename);
+ obstack_grow_str (obstack, p.c_str ());
obstack_grow_str (obstack, "\"");
if (ldi->member_name[0] != '\0')
{
obstack_grow_str (obstack, " member=\"");
p = xml_escape_text (ldi->member_name);
- obstack_grow_str (obstack, p);
- xfree (p);
+ obstack_grow_str (obstack, p.c_str ());
obstack_grow_str (obstack, "\"");
}
{
const char *input = "<this isn't=\"xml\"> &";
const char *expected_output = "<this isn't="xml"> &";
- char *actual_output = xml_escape_text (input);
+ std::string actual_output = xml_escape_text (input);
- SELF_CHECK (strcmp (actual_output, expected_output) == 0);
-
- xfree (actual_output);
+ SELF_CHECK (actual_output == expected_output);
}
}
windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
struct gdbarch *gdbarch, struct obstack *obstack)
{
- char *p;
CORE_ADDR text_offset;
obstack_grow_str (obstack, "<library name=\"");
- p = xml_escape_text (so_name);
- obstack_grow_str (obstack, p);
- xfree (p);
+ std::string p = xml_escape_text (so_name);
+ obstack_grow_str (obstack, p.c_str ());
obstack_grow_str (obstack, "\"><segment address=\"");
gdb_bfd_ref_ptr dll (gdb_bfd_open (so_name, gnutarget, -1));
/* The following calls are OK even if dll is NULL.