diff options
| -rw-r--r-- | src/xplist.c | 6 |
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\ | |||
| 59 | * | 59 | * |
| 60 | * @return The formatted string. | 60 | * @return The formatted string. |
| 61 | */ | 61 | */ |
| 62 | static char *format_string(const char *buf, int cols, int depth) | 62 | static gchar *format_string(const char *buf, int cols, int depth) |
| 63 | { | 63 | { |
| 64 | int colw = depth + cols + 1; | 64 | int colw = depth + cols + 1; |
| 65 | int len = strlen(buf); | 65 | int len = strlen(buf); |
| 66 | int nlines = len / cols + 1; | 66 | int nlines = len / cols + 1; |
| 67 | char *new_buf = (char *) malloc(nlines * colw + depth + 1); | 67 | gchar *new_buf = (gchar *) g_malloc0(nlines * colw + depth + 1); |
| 68 | int i = 0; | 68 | int i = 0; |
| 69 | int j = 0; | 69 | int j = 0; |
| 70 | 70 | ||
| @@ -76,7 +76,7 @@ static char *format_string(const char *buf, int cols, int depth) | |||
| 76 | new_buf[i * colw] = '\n'; | 76 | new_buf[i * colw] = '\n'; |
| 77 | for (j = 0; j < depth; j++) | 77 | for (j = 0; j < depth; j++) |
| 78 | new_buf[i * colw + 1 + j] = '\t'; | 78 | new_buf[i * colw + 1 + j] = '\t'; |
| 79 | memcpy(new_buf + i * colw + 1 + depth, buf + i * cols, cols); | 79 | memcpy(new_buf + i * colw + 1 + depth, buf + i * cols, (i + 1) * cols <= len ? cols : len - i * cols); |
| 80 | } | 80 | } |
| 81 | new_buf[len + (1 + depth) * nlines] = '\n'; | 81 | new_buf[len + (1 + depth) * nlines] = '\n'; |
| 82 | 82 | ||
