Skip to content

Commit 9692f7f

Browse files
committed
Guard against null pointers in actionBacktrace()
A warning was produced in GCC's LTO (GCC 13, Ubuntu 24.04) in `-O2 -flto` mode: ``` In function ‘Process_isUserlandThread’, inlined from ‘actionBacktrace’ at Action.c:621:9: Process.h:287:15: error: null pointer dereference [-Werror=null-dereference] 287 | return this->isUserlandThread; | ^ ``` It's good to add a null pointer guard anyway. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent 25460fb commit 9692f7f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Action.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,10 @@ static Htop_Reaction actionBacktrace(State *st) {
618618
const Vector* allProcesses = st->mainPanel->super.items;
619619

620620
Vector* processes = Vector_new(Class(Process), false, VECTOR_DEFAULT_SIZE);
621-
if (!Process_isUserlandThread(selectedProcess)) {
621+
if (selectedProcess && !Process_isUserlandThread(selectedProcess)) {
622622
for (int i = 0; i < Vector_size(allProcesses); i++) {
623623
Process* process = (Process *)Vector_get(allProcesses, i);
624-
if (Process_getThreadGroup(process) == Process_getThreadGroup(selectedProcess)) {
624+
if (process && Process_getThreadGroup(process) == Process_getThreadGroup(selectedProcess)) {
625625
Vector_add(processes, process);
626626
}
627627
}

0 commit comments

Comments
 (0)