1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

build: cleanup to fix clang warnings/errors

unit1309 and vtls/gtls: error: arithmetic on a null pointer treated as a
cast from integer to pointer is a GNU extension

Reported-by: Rikard Falkeborn

Fixes #2466
Closes #2468
This commit is contained in:
Daniel Stenberg 2018-04-07 11:03:18 +02:00
parent 817d1c0106
commit dc1b6c5a00
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 18 additions and 28 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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