Line 0
Link Here
|
|
|
1 |
--- src/task-manager.c 2018-06-03 18:43:41.000000000 +0300 |
2 |
+++ src/task-manager.c 2018-07-29 09:21:33.383945000 +0300 |
3 |
@@ -22,6 +22,7 @@ |
4 |
#include <glib-object.h> |
5 |
#include <glib/gi18n.h> |
6 |
#include <gtk/gtk.h> |
7 |
+#include <gmodule.h> |
8 |
|
9 |
#include "task-manager.h" |
10 |
#ifdef HAVE_WNCK |
11 |
@@ -125,12 +126,44 @@ |
12 |
static gchar * |
13 |
pretty_cmdline (gchar *cmdline, gchar *comm) |
14 |
{ |
15 |
- /* Use the printable range of 0x20-0x7E */ |
16 |
- const gchar *valid_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@" |
17 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" |
18 |
- "abcdefghijklmnopqrstuvwxyz{|}~"; |
19 |
- gchar *text = g_strstrip (g_strcanon (g_strdup (cmdline), valid_chars, ' ')); |
20 |
- gsize text_size = (gsize)strlen (text); |
21 |
+ gunichar c; |
22 |
+ gchar *ch, *text_max, *text = g_strstrip (g_strdup (cmdline)); |
23 |
+ gsize csize, text_size = (gsize)strlen (text); |
24 |
+ |
25 |
+ /* UTF-8 normalize. */ |
26 |
+ do { |
27 |
+ for (ch = text, text_max = (text + text_size); |
28 |
+ text_max > ch; |
29 |
+ text_max = (text + text_size), ch = g_utf8_next_char(ch)) { |
30 |
+ c = g_utf8_get_char_validated(ch, -1); /* If use (text_max - ch) - result is worse. */ |
31 |
+ if ((gunichar)-2 == c) { |
32 |
+ text_size = (gsize)(ch - text); |
33 |
+ (*ch) = 0; |
34 |
+ break; |
35 |
+ } |
36 |
+ if ((gunichar)-1 == c) { |
37 |
+ (*ch) = ' '; |
38 |
+ continue; |
39 |
+ } |
40 |
+ csize = (gsize)g_unichar_to_utf8(c, NULL); |
41 |
+ |
42 |
+ if (!g_unichar_isdefined(c) || |
43 |
+ !g_unichar_isprint(c) || |
44 |
+ (g_unichar_isspace(c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) || |
45 |
+ g_unichar_ismark(c) || |
46 |
+ g_unichar_istitle(c) || |
47 |
+ g_unichar_iswide(c) || |
48 |
+ g_unichar_iszerowidth(c) || |
49 |
+ g_unichar_iscntrl(c)) { |
50 |
+ if (text_max < (ch + csize)) |
51 |
+ break; |
52 |
+ memmove(ch, (ch + csize), (gsize)(text_max - (ch + csize))); |
53 |
+ text_size -= csize; |
54 |
+ } |
55 |
+ } |
56 |
+ text[text_size] = 0; |
57 |
+ } while (!g_utf8_validate(text, (gssize)text_size, NULL)); |
58 |
+ |
59 |
if (!full_cmdline && text_size > 3) |
60 |
{ |
61 |
/* Shorten full path to commands and wine applications */ |
62 |
@@ -139,7 +172,7 @@ |
63 |
gchar *p = g_strstr_len (text, (gssize)text_size, comm); |
64 |
if (p != NULL) |
65 |
{ |
66 |
- g_strlcpy (text, p, text_size); |
67 |
+ memmove (text, p, text_size); |
68 |
} |
69 |
} |
70 |
} |