aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
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