From 0fd510b3673f479637a6376db3d66dcb9f8911d0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Apr 2014 12:08:50 +0200 Subject: [PATCH] lib/socket: use proper typed constant UINT32_MAX for uint32_t typed port This was a bug on architectures with native int type less then 32 bit. Acked-by: Thomas Graf Signed-off-by: Thomas Haller --- lib/socket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/socket.c b/lib/socket.c index 00d8d6a..959b122 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -82,7 +82,7 @@ static uint32_t generate_local_port(void) nl_write_unlock(&port_map_lock); - return pid + (n << 22); + return pid + (((uint32_t)n) << 22); } } @@ -90,14 +90,14 @@ static uint32_t generate_local_port(void) /* Out of sockets in our own PID namespace, what to do? FIXME */ NL_DBG(1, "Warning: Ran out of unique local port namespace\n"); - return UINT_MAX; + return UINT32_MAX; } static void release_local_port(uint32_t port) { int nr; - if (port == UINT_MAX) + if (port == UINT32_MAX) return; nr = port >> 22; @@ -126,7 +126,7 @@ static struct nl_sock *__alloc_socket(struct nl_cb *cb) sk->s_peer.nl_family = AF_NETLINK; sk->s_seq_expect = sk->s_seq_next = time(0); sk->s_local.nl_pid = generate_local_port(); - if (sk->s_local.nl_pid == UINT_MAX) { + if (sk->s_local.nl_pid == UINT32_MAX) { nl_socket_free(sk); return NULL; }