From 77511774747d72f8e0ce4192265723bb22d785f2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 May 2021 08:55:39 +0200 Subject: [PATCH] dhcp: assert that pid_t is signed for NMDhcpClient Probably pid_t is always signed, because kill() documents that negative values have a special meaning (technically, C would automatically cast negative signed values to an unsigned pid_t type too). Anyway, NMDhcpClient at several places uses -1 as special value for "no pid". At the same time, it checks for valid PIDs with "pid > 1". That only works if pid_t is signed. Add a static assertion for that. (cherry picked from commit 92bfe09724392a4b27f919b287b08bb6945d94b1) --- src/core/dhcp/nm-dhcp-client.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index 0db931ddcd..3b0343fdd7 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -84,6 +84,11 @@ G_DEFINE_ABSTRACT_TYPE(NMDhcpClient, nm_dhcp_client, G_TYPE_OBJECT) /*****************************************************************************/ +/* we use pid=-1 for invalid PIDs. Ensure that pid_t can hold negative values. */ +G_STATIC_ASSERT(!(((pid_t) -1) > 0)); + +/*****************************************************************************/ + pid_t nm_dhcp_client_get_pid(NMDhcpClient *self) {