aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/unit1305.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/unit1305.c')
-rw-r--r--tests/unit/unit1305.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c
index 6e4bbb86..50f6da8b 100644
--- a/tests/unit/unit1305.c
+++ b/tests/unit/unit1305.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -73,26 +73,21 @@ static void unit_stop(void)
curl_global_cleanup();
}
-static Curl_addrinfo *fake_ai(void)
+static struct Curl_addrinfo *fake_ai(void)
{
- static Curl_addrinfo *ai;
+ static struct Curl_addrinfo *ai;
+ static const char dummy[]="dummy";
+ size_t namelen = sizeof(dummy); /* including the zero terminator */
- ai = calloc(1, sizeof(Curl_addrinfo));
+ ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) +
+ namelen);
if(!ai)
return NULL;
- ai->ai_canonname = strdup("dummy");
- if(!ai->ai_canonname) {
- free(ai);
- return NULL;
- }
-
- ai->ai_addr = calloc(1, sizeof(struct sockaddr_in));
- if(!ai->ai_addr) {
- free(ai->ai_canonname);
- free(ai);
- return NULL;
- }
+ ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo));
+ ai->ai_canonname = (void *)((char *)ai->ai_addr +
+ sizeof(struct sockaddr_in));
+ memcpy(ai->ai_canonname, dummy, namelen);
ai->ai_family = AF_INET;
ai->ai_addrlen = sizeof(struct sockaddr_in);