summaryrefslogtreecommitdiffstats
path: root/src/xplist.c
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-02-14 19:09:27 +0100
committerGravatar Jonathan Beck2009-02-14 19:09:27 +0100
commit8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4 (patch)
tree7b79d90ded6e64dfb45ea6c9b742904db6e7f13b /src/xplist.c
parent3c458d22fdad10b41d810248c6a8efbe5b23f515 (diff)
downloadlibplist-8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4.tar.gz
libplist-8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4.tar.bz2
Fix Invalid memory read and match g_free with g_malloc.
Diffstat (limited to 'src/xplist.c')
-rw-r--r--src/xplist.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/xplist.c b/src/xplist.c
index 525706c..e281b4f 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -59,12 +59,12 @@ static const char *plist_base = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
*
* @return The formatted string.
*/
-static char *format_string(const char *buf, int cols, int depth)
+static gchar *format_string(const char *buf, int cols, int depth)
{
int colw = depth + cols + 1;
int len = strlen(buf);
int nlines = len / cols + 1;
- char *new_buf = (char *) malloc(nlines * colw + depth + 1);
+ gchar *new_buf = (gchar *) g_malloc0(nlines * colw + depth + 1);
int i = 0;
int j = 0;
@@ -76,7 +76,7 @@ static char *format_string(const char *buf, int cols, int depth)
new_buf[i * colw] = '\n';
for (j = 0; j < depth; j++)
new_buf[i * colw + 1 + j] = '\t';
- memcpy(new_buf + i * colw + 1 + depth, buf + i * cols, cols);
+ memcpy(new_buf + i * colw + 1 + depth, buf + i * cols, (i + 1) * cols <= len ? cols : len - i * cols);
}
new_buf[len + (1 + depth) * nlines] = '\n';