From 94400f32e9016d2eaea2db583f6e213c36b1eb1d Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Sat, 14 Apr 2018 22:42:04 +0200 Subject: all: Refactor malloc+memset to use calloc When a zeroed out allocation is required, use calloc() rather than malloc() followed by an explicit memset(). The result will be the same, but using calloc() everywhere increases consistency in the codebase and avoids the risk of subtle bugs when code is injected between malloc and memset by accident. Closes https://github.com/curl/curl/pull/2497 --- tests/server/sockfilt.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 40f5bdb48..844d35a4e 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -727,24 +727,20 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds, } /* allocate internal array for the internal data */ - data = malloc(nfds * sizeof(struct select_ws_data)); + data = calloc(nfds, sizeof(struct select_ws_data)); if(data == NULL) { errno = ENOMEM; return -1; } /* allocate internal array for the internal event handles */ - handles = malloc(nfds * sizeof(HANDLE)); + handles = calloc(nfds, sizeof(HANDLE)); if(handles == NULL) { free(data); errno = ENOMEM; return -1; } - /* clear internal arrays */ - memset(data, 0, nfds * sizeof(struct select_ws_data)); - memset(handles, 0, nfds * sizeof(HANDLE)); - /* loop over the handles in the input descriptor sets */ for(fds = 0; fds < nfds; fds++) { networkevents = 0; -- cgit v1.2.3