From 7bfa466abe65ff14d530ae16c344cdc06d5145ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 27 Jan 2021 15:12:15 +0100 Subject: [PATCH] Linux: silence UBSAN implicit conversions pgrp and session might be -1 linux/LinuxProcessList.c:312:20: runtime error: implicit conversion from type 'unsigned long' of value 18446744073709551615 (64-bit, unsigned) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:312:20 in linux/LinuxProcessList.c:314:23: runtime error: implicit conversion from type 'unsigned long' of value 18446744073709551615 (64-bit, unsigned) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:314:23 in --- Process.h | 4 ++-- linux/LinuxProcessList.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Process.h b/Process.h index fce5017d..e9c42622 100644 --- a/Process.h +++ b/Process.h @@ -76,10 +76,10 @@ typedef struct Process_ { pid_t tgid; /* Process group identifier */ - unsigned int pgrp; + int pgrp; /* Session identifier */ - unsigned int session; + int session; /* Foreground group identifier of the controlling terminal */ int tpgid; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5c15c2e1..081b31e0 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -316,11 +316,11 @@ static bool LinuxProcessList_readStatFile(Process* process, openat_arg_t procFd, location += 1; /* (5) pgrp - %d */ - process->pgrp = strtoul(location, &location, 10); + process->pgrp = strtol(location, &location, 10); location += 1; /* (6) session - %d */ - process->session = strtoul(location, &location, 10); + process->session = strtol(location, &location, 10); location += 1; /* (7) tty_nr - %d */