Fix crash when _NET_WM_ICON is set but empty

This commit is contained in:
o9000 2017-04-27 09:04:16 +02:00
parent f351b6fd8e
commit 82776df9d6
2 changed files with 20 additions and 17 deletions

View file

@ -276,14 +276,13 @@ void task_update_icon(Task *task)
Imlib_Image img = NULL; Imlib_Image img = NULL;
if (!img) { if (!img) {
int i; int len;
gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &i); gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &len);
if (data) { if (data && len > 0) {
// get ARGB icon // get ARGB icon
int w, h; int w, h;
gulong *tmp_data; gulong *tmp_data = get_best_icon(data, get_icon_count(data, len), len, &w, &h, panel->g_task.icon_size1);
if (tmp_data) {
tmp_data = get_best_icon(data, get_icon_count(data, i), i, &w, &h, panel->g_task.icon_size1);
DATA32 icon_data[w * h]; DATA32 icon_data[w * h];
for (int j = 0; j < w * h; ++j) for (int j = 0; j < w * h; ++j)
icon_data[j] = tmp_data[j]; icon_data[j] = tmp_data[j];
@ -295,6 +294,7 @@ void task_update_icon(Task *task)
w, w,
h, h,
task->title ? task->title : "task"); task->title ? task->title : "task");
}
XFree(data); XFree(data);
} }
} }

View file

@ -277,6 +277,9 @@ int get_icon_count(gulong *data, int num)
gulong *get_best_icon(gulong *data, int icon_count, int num, int *iw, int *ih, int best_icon_size) gulong *get_best_icon(gulong *data, int icon_count, int num, int *iw, int *ih, int best_icon_size)
{ {
if (icon_count < 1 || num < 1)
return NULL;
int width[icon_count], height[icon_count], pos, i, w, h; int width[icon_count], height[icon_count], pos, i, w, h;
gulong *icon_data[icon_count]; gulong *icon_data[icon_count];