From 91ad56ac30523670d5e972d2b0e4208db330b912 Mon Sep 17 00:00:00 2001 From: Mikhail Efremov Date: Tue, 14 Oct 2014 19:10:26 +0400 Subject: [PATCH] Fix UTF-8 strings in the pretty_cmdline(). 1. g_utf8_strlen() returns length of the string in characters, not in bytes. So this value can not be used as argument for snprintf(). 2. snprintf() can not be used with overlapping buffers (C-11 standard, 7.21.6.5 paragraph 2). So count the number of bytes (not characters) with strlen() and use memmove() then. --- src/task-manager.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/task-manager.c b/src/task-manager.c index 4619a44..1d0a707 100644 --- a/src/task-manager.c +++ b/src/task-manager.c @@ -146,7 +146,9 @@ pretty_cmdline (gchar *cmdline, gchar *comm) gchar *p = g_strstr_len (text, -1, comm); if (p != NULL) { - g_snprintf (text, g_utf8_strlen (text, -1), "%s", p); + /* p points to substring in the text, + * so just move strlen(p) bytes + the terminating nul character */ + memmove (text, p, strlen (p) + 1); } } } -- 2.0.4