This is an automated email from Gerrit.

"zapb <[email protected]>" just uploaded a new patch set to Gerrit, which you can 
find at https://review.openocd.org/c/openocd/+/9582

-- gerrit

commit 2e96a667f6f3b2b96fd6387daad7620af8195519
Author: Marc Schink <[email protected]>
Date:   Sat Apr 18 16:19:56 2026 +0200

    adapters/xvc: Fix xvc_init_tcp()
    
    Avoid calling setsockopt() on an invalid socket when the TCP connection
    setup fails.
    
    While at it, restructure the code and apply const-correctness.
    
    Change-Id: I1dc3da89321c5d0b4c76c145501c80206a3c9de4
    Signed-off-by: Marc Schink <[email protected]>

diff --git a/src/jtag/drivers/xvc.c b/src/jtag/drivers/xvc.c
index 8a1bc7c7fd..d5a5810f35 100644
--- a/src/jtag/drivers/xvc.c
+++ b/src/jtag/drivers/xvc.c
@@ -324,10 +324,13 @@ static int xvc_reset(int trst, int srst)
 
 static int xvc_init_tcp(int *fd)
 {
-       struct addrinfo hints = {.ai_family = AF_UNSPEC, .ai_socktype = 
SOCK_STREAM};
-
        LOG_INFO("Connecting to %s:%s", xvc_host ? xvc_host : "localhost", 
xvc_port);
 
+       const struct addrinfo hints = {
+               .ai_family = AF_UNSPEC,
+               .ai_socktype = SOCK_STREAM
+       };
+
        struct addrinfo *result;
        // Obtain address(es) matching host/port.
        int s = getaddrinfo(xvc_host, xvc_port, &hints, &result);
@@ -350,20 +353,12 @@ static int xvc_init_tcp(int *fd)
                if (*fd ==  (int)INVALID_SOCKET)
                        continue;
 #endif
-
                if (connect(*fd, rp->ai_addr, rp->ai_addrlen) != -1)
                        break;
 
                close_socket(*fd);
        }
 
-       /* We work hard to collapse the writes into the minimum number, so when
-        * we write something we want to get it to the other end of the
-        * connection as fast as possible. */
-       int one = 1;
-       // On Windows optval has to be a const char *.
-       setsockopt(*fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one, 
sizeof(one));
-
        freeaddrinfo(result);
 
        if (!rp) {
@@ -371,6 +366,13 @@ static int xvc_init_tcp(int *fd)
                return ERROR_FAIL;
        }
 
+       /* We work hard to collapse the writes into the minimum number, so when
+        * we write something we want to get it to the other end of the
+        * connection as fast as possible. */
+       int one = 1;
+       // On Windows optval has to be a const char *.
+       setsockopt(*fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one, 
sizeof(one));
+
        return ERROR_OK;
 }
 

-- 

Reply via email to