diff options
-rw-r--r-- | lib/vtls/gtls.c | 10 | ||||
-rw-r--r-- | lib/warnless.h | 7 | ||||
-rw-r--r-- | tests/unit/unit1309.c | 29 |
3 files changed, 18 insertions, 28 deletions
diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index 3f30b6c8c..688e83807 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -152,7 +152,8 @@ static int gtls_mapped_sockerrno(void) static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len) { - ssize_t ret = swrite(CURLX_POINTER_TO_INTEGER_CAST(s), buf, len); + curl_socket_t sock = *(curl_socket_t *)s; + ssize_t ret = swrite(sock, buf, len); #if defined(USE_WINSOCK) && !defined(GNUTLS_MAPS_WINSOCK_ERRORS) if(ret < 0) gnutls_transport_set_global_errno(gtls_mapped_sockerrno()); @@ -162,7 +163,8 @@ static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len) static ssize_t Curl_gtls_pull(void *s, void *buf, size_t len) { - ssize_t ret = sread(CURLX_POINTER_TO_INTEGER_CAST(s), buf, len); + curl_socket_t sock = *(curl_socket_t *)s; + ssize_t ret = sread(sock, buf, len); #if defined(USE_WINSOCK) && !defined(GNUTLS_MAPS_WINSOCK_ERRORS) if(ret < 0) gnutls_transport_set_global_errno(gtls_mapped_sockerrno()); @@ -848,7 +850,7 @@ gtls_connect_step1(struct connectdata *conn, } else { /* file descriptor for the socket */ - transport_ptr = CURLX_INTEGER_TO_POINTER_CAST(conn->sock[sockindex]); + transport_ptr = &conn->sock[sockindex]; gnutls_transport_push = Curl_gtls_push; gnutls_transport_pull = Curl_gtls_pull; } diff --git a/lib/warnless.h b/lib/warnless.h index efd552a60..f6a2d744b 100644 --- a/lib/warnless.h +++ b/lib/warnless.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -26,11 +26,6 @@ #include <curl/curl.h> /* for curl_socket_t */ #endif -#define CURLX_POINTER_TO_INTEGER_CAST(p) \ - ((char *)(p) - (char *)NULL) -#define CURLX_INTEGER_TO_POINTER_CAST(i) \ - ((void *)((char *)NULL + (i))) - unsigned short curlx_ultous(unsigned long ulnum); unsigned char curlx_ultouc(unsigned long ulnum); diff --git a/tests/unit/unit1309.c b/tests/unit/unit1309.c index 9a07c9332..7d3c00017 100644 --- a/tests/unit/unit1309.c +++ b/tests/unit/unit1309.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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,6 +73,7 @@ UNITTEST_START struct Curl_tree *root, *removed; struct Curl_tree nodes[NUM_NODES*3]; + size_t storage[NUM_NODES*3]; int rc; int i, j; struct curltime tv_now = {0, 0}; @@ -81,14 +82,11 @@ UNITTEST_START /* add nodes */ for(i = 0; i < NUM_NODES; i++) { struct curltime key; - size_t payload; key.tv_sec = 0; key.tv_usec = (541*i)%1023; - payload = (size_t) key.tv_usec; - - /* for simplicity */ - nodes[i].payload = CURLX_INTEGER_TO_POINTER_CAST(payload); + storage[i] = key.tv_usec; + nodes[i].payload = &storage[i]; root = Curl_splayinsert(key, root, &nodes[i]); } @@ -99,8 +97,8 @@ UNITTEST_START int rem = (i + 7)%NUM_NODES; printf("Tree look:\n"); splayprint(root, 0, 1); - printf("remove pointer %d, payload %ld\n", rem, - CURLX_POINTER_TO_INTEGER_CAST(nodes[rem].payload)); + printf("remove pointer %d, payload %zd\n", rem, + *(size_t *)nodes[rem].payload); rc = Curl_splayremovebyaddr(root, &nodes[rem], &root); if(rc) { /* failed! */ @@ -120,9 +118,8 @@ UNITTEST_START /* add some nodes with the same key */ for(j = 0; j <= i % 3; j++) { - size_t payload = key.tv_usec*10 + j; - /* for simplicity */ - nodes[i * 3 + j].payload = CURLX_INTEGER_TO_POINTER_CAST(payload); + storage[i * 3 + j] = key.tv_usec*10 + j; + nodes[i * 3 + j].payload = &storage[i * 3 + j]; root = Curl_splayinsert(key, root, &nodes[i * 3 + j]); } } @@ -133,9 +130,9 @@ UNITTEST_START tv_now.tv_usec = i; root = Curl_splaygetbest(tv_now, root, &removed); while(removed != NULL) { - printf("removed payload %ld[%ld]\n", - CURLX_POINTER_TO_INTEGER_CAST(removed->payload) / 10, - CURLX_POINTER_TO_INTEGER_CAST(removed->payload) % 10); + printf("removed payload %zd[%zd]\n", + (*(size_t *)removed->payload) / 10, + (*(size_t *)removed->payload) % 10); root = Curl_splaygetbest(tv_now, root, &removed); } } @@ -143,7 +140,3 @@ UNITTEST_START fail_unless(root == NULL, "tree not empty when it should be"); UNITTEST_STOP - - - - |