Skip to content

Commit

Permalink
socket: explicitly cast time() to uint32_t
Browse files Browse the repository at this point in the history
Coverity warns about this. Try to avoid the warning by casting.
We only use time() to get some (very little) entropy. The cast
is fine.
  • Loading branch information
thom311 committed Dec 1, 2023
1 parent 46e8739 commit 57e0170
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/socket.c
Expand Up @@ -73,7 +73,7 @@ static uint32_t generate_local_port(void)
nl_write_lock(&port_map_lock);

if (idx_state == 0) {
uint32_t t = time(NULL);
uint32_t t = (uint32_t) time(NULL);

/* from time to time (on average each 2^15 calls), the idx_state will
* be zero again. No problem, just "seed" anew with time(). */
Expand Down Expand Up @@ -190,7 +190,8 @@ static struct nl_sock *__alloc_socket(struct nl_cb *cb)
sk->s_cb = nl_cb_get(cb);
sk->s_local.nl_family = AF_NETLINK;
sk->s_peer.nl_family = AF_NETLINK;
sk->s_seq_expect = sk->s_seq_next = time(NULL);
sk->s_seq_next = (unsigned int) time(NULL);
sk->s_seq_expect = sk->s_seq_next;

/* the port is 0 (unspecified), meaning NL_OWN_PORT */
sk->s_flags = NL_OWN_PORT;
Expand Down

0 comments on commit 57e0170

Please sign in to comment.