From 5485887c4793cb73579f069fe0181ccfbb0db87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Mon, 24 Jun 2024 14:19:12 +0800 Subject: [PATCH] Check against EVUTIL_INVALID_SOCKET --- test/regress.c | 2 +- test/regress_main.c | 2 +- test/regress_util.c | 2 +- test/regress_zlib.c | 2 +- test/test-changelist.c | 14 +++++++++----- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test/regress.c b/test/regress.c index 9a15285c..473e92ef 100644 --- a/test/regress.c +++ b/test/regress.c @@ -391,7 +391,7 @@ test_simpleclose_rw(void *ptr) { /* Test that a close of FD is detected as a read and as a write. */ struct event_base *base = event_base_new(); - evutil_socket_t pair1[2]={-1,-1}, pair2[2] = {-1, -1}; + evutil_socket_t pair1[2]={EVUTIL_INVALID_SOCKET,EVUTIL_INVALID_SOCKET}, pair2[2] = {EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET}; evutil_socket_t *to_close[2]; struct event *rev=NULL, *wev=NULL, *closeev=NULL; struct timeval tv; diff --git a/test/regress_main.c b/test/regress_main.c index 4888f1a0..e780e8b2 100644 --- a/test/regress_main.c +++ b/test/regress_main.c @@ -249,7 +249,7 @@ void * basic_test_setup(const struct testcase_t *testcase) { struct event_base *base = NULL; - evutil_socket_t spair[2] = { -1, -1 }; + evutil_socket_t spair[2] = { EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET }; struct basic_test_data *data = NULL; #if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED) diff --git a/test/regress_util.c b/test/regress_util.c index b13bb1e5..54e32c06 100644 --- a/test/regress_util.c +++ b/test/regress_util.c @@ -1731,7 +1731,7 @@ test_evutil_win_socketpair(void *arg) struct basic_test_data *data = arg; const int inet = strstr(data->setup_data, "inet") != NULL; int family = inet ? AF_INET : AF_UNIX; - evutil_socket_t fd[2] = { -1, -1 }; + evutil_socket_t fd[2] = { EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET }; int r; int type; ev_socklen_t typelen; diff --git a/test/regress_zlib.c b/test/regress_zlib.c index e0becccc..a00479e7 100644 --- a/test/regress_zlib.c +++ b/test/regress_zlib.c @@ -282,7 +282,7 @@ test_bufferevent_zlib(void *arg) char buffer[8333]; z_stream *z_input, *z_output; int i, r; - evutil_socket_t pair[2] = {-1, -1}; + evutil_socket_t pair[2] = {EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET}; (void)arg; infilter_calls = outfilter_calls = readcb_finished = writecb_finished diff --git a/test/test-changelist.c b/test/test-changelist.c index 3869dd22..178589c8 100644 --- a/test/test-changelist.c +++ b/test/test-changelist.c @@ -165,7 +165,7 @@ main(int argc, char **argv) struct event* timeout = NULL; struct event_base* base = NULL; - evutil_socket_t pair[2]; + evutil_socket_t pair[2] = {EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET}; struct timeval tv; struct cpu_usage_timer timer; @@ -188,12 +188,16 @@ main(int argc, char **argv) /* Initialize a timeout to terminate the test */ timeout = evtimer_new(base,timeout_cb,&timeout); - if (timeout == NULL) + if (timeout == NULL) { + perror("evtimer_new"); goto err; + } /* and watch for writability on one end of the pipe */ ev = event_new(base,pair[1],EV_WRITE | EV_PERSIST, write_cb, &ev); - if (ev == NULL) + if (ev == NULL) { + perror("event_new"); goto err; + } tv.tv_sec = 1; tv.tv_usec = 500*1000; @@ -228,9 +232,9 @@ err: event_free(ev); if (timeout) event_free(timeout); - if (pair[0] >= 0) + if (pair[0] != EVUTIL_INVALID_SOCKET) evutil_closesocket(pair[0]); - if (pair[1] >= 0) + if (pair[1] != EVUTIL_INVALID_SOCKET) evutil_closesocket(pair[1]); if (base) event_base_free(base);