[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 90/208: gtls: fix build when sizeof(long) < sizeof(
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 90/208: gtls: fix build when sizeof(long) < sizeof(void *) |
Date: |
Wed, 09 Aug 2017 17:34:47 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to annotated tag gnurl-7.55.0
in repository gnurl.
commit c0cdc68c7eacaa4fda3e2324f8618b6bbe038983
Author: Johannes Schindelin <address@hidden>
AuthorDate: Mon Jun 26 23:15:22 2017 +0200
gtls: fix build when sizeof(long) < sizeof(void *)
- Change gnutls pointer/int macros to pointer/curl_socket_t.
Prior to this change they used long type as well.
The size of the `long` data type can be shorter than that of pointer
types. This is the case most notably on Windows.
If C99 were acceptable, we could simply use `intptr_t` here. But we
want to retain C89 compatibility.
Simply use the trick of performing pointer arithmetic with the NULL
pointer: to convert an integer `i` to a pointer, simply take the
address of the `i`th element of a hypothetical character array
starting at address NULL. To convert back, simply cast the pointer
difference.
Thanks to Jay Satiro for the initial modification to use curl_socket_t
instead of int/long.
Closes #1617
Signed-off-by: Johannes Schindelin <address@hidden>
---
lib/vtls/gtls.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c
index cbbb61f76..d55f995e8 100644
--- a/lib/vtls/gtls.c
+++ b/lib/vtls/gtls.c
@@ -60,15 +60,13 @@
/* The last #include file should be: */
#include "memdebug.h"
-/*
- Some hackish cast macros based on:
- https://developer.gnome.org/glib/unstable/glib-Type-Conversion-Macros.html
-*/
-#ifndef GNUTLS_POINTER_TO_INT_CAST
-#define GNUTLS_POINTER_TO_INT_CAST(p) ((int) (long) (p))
+#ifndef GNUTLS_POINTER_TO_SOCKET_CAST
+#define GNUTLS_POINTER_TO_SOCKET_CAST(p) \
+ ((curl_socket_t) ((char *)(p) - (char *)NULL))
#endif
-#ifndef GNUTLS_INT_TO_POINTER_CAST
-#define GNUTLS_INT_TO_POINTER_CAST(i) ((void *) (long) (i))
+#ifndef GNUTLS_SOCKET_TO_POINTER_CAST
+#define GNUTLS_SOCKET_TO_POINTER_CAST(s) \
+ ((void *) ((char *)NULL + (s)))
#endif
/* Enable GnuTLS debugging by defining GTLSDEBUG */
@@ -153,7 +151,7 @@ static int gtls_mapped_sockerrno(void)
static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len)
{
- ssize_t ret = swrite(GNUTLS_POINTER_TO_INT_CAST(s), buf, len);
+ ssize_t ret = swrite(GNUTLS_POINTER_TO_SOCKET_CAST(s), buf, len);
#if defined(USE_WINSOCK) && !defined(GNUTLS_MAPS_WINSOCK_ERRORS)
if(ret < 0)
gnutls_transport_set_global_errno(gtls_mapped_sockerrno());
@@ -163,7 +161,7 @@ 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(GNUTLS_POINTER_TO_INT_CAST(s), buf, len);
+ ssize_t ret = sread(GNUTLS_POINTER_TO_SOCKET_CAST(s), buf, len);
#if defined(USE_WINSOCK) && !defined(GNUTLS_MAPS_WINSOCK_ERRORS)
if(ret < 0)
gnutls_transport_set_global_errno(gtls_mapped_sockerrno());
@@ -850,7 +848,7 @@ gtls_connect_step1(struct connectdata *conn,
}
else {
/* file descriptor for the socket */
- transport_ptr = GNUTLS_INT_TO_POINTER_CAST(conn->sock[sockindex]);
+ transport_ptr = GNUTLS_SOCKET_TO_POINTER_CAST(conn->sock[sockindex]);
gnutls_transport_push = Curl_gtls_push;
gnutls_transport_pull = Curl_gtls_pull;
}
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 56/208: travis: enable typecheck-gcc warnings, (continued)
- [GNUnet-SVN] [gnurl] 56/208: travis: enable typecheck-gcc warnings, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 55/208: typecheck-gcc: add support for CURLINFO_OFF_T, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 199/208: tftp: reject file name lengths that don't fit, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 111/208: asyn-thread.c: fix unused variable warnings on macOS, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 190/208: FTP: skip unnecessary CWD when in nocwd mode, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 63/208: CURLINFO_REDIRECT_URL.3: mention the CURLOPT_MAXREDIRS case, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 157/208: darwinssl: fix variable type mistake (regression), gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 143/208: travis: enable warnings also in release mode, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 01/208: includes: remove curl/curlbuild.h and curl/curlrules.h, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 65/208: curl-compilers.m4: fix unknown-warning-option on Apple clang, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 90/208: gtls: fix build when sizeof(long) < sizeof(void *),
gnunet <=
- [GNUnet-SVN] [gnurl] 120/208: test1452: add telnet negotiation, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 96/208: test1451: add SMB support to the testbed, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 26/208: HTTPS-Proxy: don't offer h2 for https proxy connections, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 155/208: checksrc: escape open brace in regex, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 147/208: rtspd: fix MSVC level 4 warning, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 64/208: progress: fix "time spent", broke in adef394ac, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 162/208: splay: fix signed/unsigned mismatch warning, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 204/208: configure: fix recv/send/select detection on Android, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 186/208: darwin: silence compiler warnings, gnunet, 2017/08/09
- [GNUnet-SVN] [gnurl] 172/208: multi: fix request timer management, gnunet, 2017/08/09