Fix UBSan errors

This commit is contained in:
correctmost
2024-01-24 14:03:22 +00:00
committed by Gaël Bonithon
parent 7ba61f749b
commit 9bf1713e82
3 changed files with 10 additions and 4 deletions

View File

@@ -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));

View File

@@ -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);

View File

@@ -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)
{