aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-09-16 14:19:31 +0200
committerSimon Marchi <simon.marchi@ericsson.com>2017-09-16 14:19:31 +0200
commit5e1875543df7413d3cbc3831390445e347064b75 (patch)
tree215e09584279387448ae183671588f0bac07a1f6 /gdb/common
parentc3d7b541fa920e6ecb0f06ffe1e0e3f070fa295d (diff)
downloadgdb-5e1875543df7413d3cbc3831390445e347064b75.zip
gdb-5e1875543df7413d3cbc3831390445e347064b75.tar.gz
gdb-5e1875543df7413d3cbc3831390445e347064b75.tar.bz2
Make xml_escape_text return an std::string
This is a simple replacement, it allows removing some manual free'ing in the callers. gdb/ChangeLog: * 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. gdb/gdbserver/ChangeLog: * linux-low.c (linux_qxfer_libraries_svr4): Adjust to change of return type of xml_escape_text. * server.c (emit_dll_description): Likewise.
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/buffer.c6
-rw-r--r--gdb/common/xml-utils.c49
-rw-r--r--gdb/common/xml-utils.h2
3 files changed, 14 insertions, 43 deletions
diff --git a/gdb/common/buffer.c b/gdb/common/buffer.c
index c5eb169..70d91e6 100644
--- a/gdb/common/buffer.c
+++ b/gdb/common/buffer.c
@@ -88,7 +88,6 @@ buffer_xml_printf (struct buffer *buffer, const char *format, ...)
if (percent)
{
char buf[32];
- char *p;
char *str = buf;
const char *f_old = f;
@@ -163,9 +162,8 @@ buffer_xml_printf (struct buffer *buffer, const char *format, ...)
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;
diff --git a/gdb/common/xml-utils.c b/gdb/common/xml-utils.c
index b5fe442..c6dd2fb 100644
--- a/gdb/common/xml-utils.c
+++ b/gdb/common/xml-utils.c
@@ -20,64 +20,37 @@
#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, "&apos;");
- special += 5;
+ result += "&apos;";
break;
case '\"':
- strcpy (result + i + special, "&quot;");
- special += 5;
+ result += "&quot;";
break;
case '&':
- strcpy (result + i + special, "&amp;");
- special += 4;
+ result += "&amp;";
break;
case '<':
- strcpy (result + i + special, "&lt;");
- special += 3;
+ result += "&lt;";
break;
case '>':
- strcpy (result + i + special, "&gt;");
- special += 3;
+ result += "&gt;";
break;
default:
- result[i + special] = text[i];
+ result += text[i];
break;
}
- result[i + special] = '\0';
return result;
}
diff --git a/gdb/common/xml-utils.h b/gdb/common/xml-utils.h
index d138bab..f69f5f5 100644
--- a/gdb/common/xml-utils.h
+++ b/gdb/common/xml-utils.h
@@ -23,6 +23,6 @@
/* 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