From 3d5b6d9282e584557999772d3cedd7e8ceddabbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 23 May 2021 15:21:51 +0200 Subject: Fix assert failure on short running thread The following assert failure might happen on short running threads with an empty comm value in /proc/${pid}/stat: htop: Process.c:1159: void Process_updateCmdline(Process *, const char *, int, int): Assertion `(cmdline && basenameStart < (int)strlen(cmdline)) || (!cmdline && basenameStart == 0)' failed. The specific task is: comm='' exe='(null)' cmdline='/usr/bin/ruby /usr/bin/how-can-i-help --apt' So basenameStart is 0, while strlen(cmdline) is also 0. --- linux/LinuxProcessList.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'linux/LinuxProcessList.c') diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6d3bbc84..e262ce7c 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1351,10 +1351,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ } } - char command[MAX_NAME + 1]; + char statCommand[MAX_NAME + 1]; unsigned long long int lasttimes = (lp->utime + lp->stime); unsigned long int tty_nr = proc->tty_nr; - if (! LinuxProcessList_readStatFile(proc, procFd, command, sizeof(command))) + if (! LinuxProcessList_readStatFile(proc, procFd, statCommand, sizeof(statCommand))) goto errorReadingProcess; if (tty_nr != proc->tty_nr && this->ttyDrivers) { @@ -1431,11 +1431,11 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ LinuxProcessList_readCwd(lp, procFd); } - if (proc->state == 'Z' && !proc->cmdline) { - Process_updateCmdline(proc, command, 0, 0); + if (proc->state == 'Z' && !proc->cmdline && statCommand[0]) { + Process_updateCmdline(proc, statCommand, 0, strlen(statCommand)); } else if (Process_isThread(proc)) { - if (settings->showThreadNames || Process_isKernelThread(proc)) { - Process_updateCmdline(proc, command, 0, 0); + if ((settings->showThreadNames || Process_isKernelThread(proc)) && statCommand[0]) { + Process_updateCmdline(proc, statCommand, 0, strlen(statCommand)); } if (Process_isKernelThread(proc)) { -- cgit v1.2.3