From 59cb7ef5a9a2a84d2034f93c398948cf8ba0b4fa Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 11 May 2024 13:58:23 +0800 Subject: [PATCH] Fix clang-analyzer-unix.StdCLibraryFunctions ``` /home/chiller/Desktop/git/ddnet/src/base/system.cpp:1989:10: error: The 1st argument to 'connect' is < 0 but should be >= 0 [clang-analyzer-unix.StdCLibraryFunctions,-warnings-as-errors] 1989 | return connect(sock->ipv4sock, (struct sockaddr *)&addr, sizeof(addr)); | ^ ``` --- src/base/system.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/base/system.cpp b/src/base/system.cpp index 514c92d5b..a7e6a2b88 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -1987,6 +1987,8 @@ int net_tcp_connect(NETSOCKET sock, const NETADDR *a) { struct sockaddr_in addr; netaddr_to_sockaddr_in(a, &addr); + if(sock->ipv4sock < 0) + return -2; return connect(sock->ipv4sock, (struct sockaddr *)&addr, sizeof(addr)); } @@ -1994,6 +1996,8 @@ int net_tcp_connect(NETSOCKET sock, const NETADDR *a) { struct sockaddr_in6 addr; netaddr_to_sockaddr_in6(a, &addr); + if(sock->ipv6sock < 0) + return -2; return connect(sock->ipv6sock, (struct sockaddr *)&addr, sizeof(addr)); }