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 92bfe09724)
This commit is contained in:
Thomas Haller 2021-05-14 08:55:39 +02:00
parent 8444188c49
commit 7751177474
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

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