From 8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sat, 14 Feb 2009 19:09:27 +0100 Subject: Fix Invalid memory read and match g_free with g_malloc. --- src/xplist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/xplist.c') 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 = "\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'; -- cgit v1.1-32-gdbae