From 9bf1713e826b17ab5e847ee42b264a129af3b71d Mon Sep 17 00:00:00 2001 From: correctmost <11866-correctmost@users.noreply.gitlab.xfce.org> Date: Wed, 24 Jan 2024 14:03:22 +0000 Subject: [PATCH] Fix UBSan errors --- src/app-manager.c | 3 +++ src/task-manager-linux.c | 2 +- src/task-manager.c | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app-manager.c b/src/app-manager.c index bf546b3..2947cfd 100644 --- a/src/app-manager.c +++ b/src/app-manager.c @@ -172,6 +172,9 @@ apps_lookup_pid (GArray *apps, GPid pid) { App tapp; + if (apps->data == NULL) + return (NULL); + tapp.pid = pid; return (bsearch(&tapp, apps->data, apps->len, sizeof(App), app_pid_compare_fn)); diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c index 7ac1ad8..1d8542d 100644 --- a/src/task-manager-linux.c +++ b/src/task-manager-linux.c @@ -153,7 +153,7 @@ get_task_cmdline (Task *task) for (i = 0; (c = fgetc (file)) != EOF && i < (gint)sizeof (task->cmdline) - 1; i++) task->cmdline[i] = (c == '\0') ? ' ' : (gchar)c; task->cmdline[i] = '\0'; - if (task->cmdline[i-1] == ' ') + if (i > 0 && task->cmdline[i-1] == ' ') task->cmdline[i-1] = '\0'; fclose (file); diff --git a/src/task-manager.c b/src/task-manager.c index 6c725b0..0549b31 100644 --- a/src/task-manager.c +++ b/src/task-manager.c @@ -333,9 +333,12 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest static gboolean task_list_find_for_pid (GArray *task_list, GPid pid, Task **task, guint *idx) { - Task *task_tmp, tkey; - tkey.pid = pid; - task_tmp = bsearch(&tkey, task_list->data, task_list->len, sizeof(Task), task_pid_compare_fn); + Task *task_tmp = NULL, tkey; + + if (task_list->data != NULL) { + tkey.pid = pid; + task_tmp = bsearch(&tkey, task_list->data, task_list->len, sizeof(Task), task_pid_compare_fn); + } if (NULL != task) {