[gnutls-dev] Re: Compiler warnings on 64bit archs

Simon Josefsson jas at extundo.com
Tue Jun 27 12:07:56 CEST 2006


Andreas Metzler <ametzler at downhill.at.eu.org> writes:

> On 2006-06-16 Andreas Metzler <ametzler at downhill.at.eu.org> wrote:
>> On 2006-06-16 Simon Josefsson <jas at extundo.com> wrote:
>>> Andreas Metzler <ametzler at downhill.at.eu.org> writes:
> [...]
>>>> ------------------------
>>>> gnutls_buffers.c:268: warning: cast from pointer to integer of different size
>>>> gnutls_buffers.c:704: warning: cast from pointer to integer of different size
>>> ...
>
>>> Storing integers within pointers is safe, isn't it?  Compare:
>>> http://developer.gnome.org/doc/API/2.0/glib/glib-Type-Conversion-Macros.html
>
>> I did not know this page. ;-)
>> <quote>
>> The problem is that on some systems you need to do this:
>> p = (void*) (long) 42;
>> i = (int) (long) p;
>> </quote>
> [...]
>
> Attached a small prrof of concept patch showing how this could be
> done, eliminating the warnings for gnutls_buffers.c. I have put the
> macros in gnutls.h, it might be better to not make them part of the
> GnuTLS API, though.

Thanks for looking into this.  I've installed the following patch.
Could you test the 2006-06-28 (or later) daily snapshot to see if it
works for you?

Index: configure.in
===================================================================
RCS file: /cvs/gnutls/gnutls/configure.in,v
retrieving revision 2.428
diff -u -p -r2.428 configure.in
--- configure.in	22 Jun 2006 11:54:43 -0000	2.428
+++ configure.in	27 Jun 2006 10:05:44 -0000
@@ -200,6 +200,20 @@ AC_MSG_RESULT([***
 AC_CHECK_SIZEOF(unsigned long, 4)
 AC_CHECK_SIZEOF(unsigned int, 4)
 
+# For storing integers in pointers without warnings
+# http://developer.gnome.org/doc/API/2.0/glib/glib-Type-Conversion-Macros.html#desc
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(int)
+case $ac_cv_sizeof_void_p in
+  $ac_cv_sizeof_long)
+    AC_DEFINE(GNUTLS_POINTER_TO_INT_CAST, [(long)],
+              [Additional cast to bring void* to a type castable to int.])
+    ;;
+  *)
+    AC_DEFINE(GNUTLS_POINTER_TO_INT_CAST, [])
+    ;;
+esac
+
 # For some systems we know that we have ld_version scripts.
 # Use it then as default.
 have_ld_version_script=no
Index: lib/gnutls_buffers.c
===================================================================
RCS file: /cvs/gnutls/gnutls/lib/gnutls_buffers.c,v
retrieving revision 2.126
diff -u -p -r2.126 gnutls_buffers.c
--- lib/gnutls_buffers.c	15 Dec 2005 13:24:29 -0000	2.126
+++ lib/gnutls_buffers.c	27 Jun 2006 10:05:44 -0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation
+ * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation
  *
  * Author: Nikos Mavroyanopoulos
  *
@@ -77,6 +77,8 @@ RET (int err)
 # include <io_debug.h>
 #endif
 
+#define GNUTLS_POINTER_TO_INT(_) ((int) GNUTLS_POINTER_TO_INT_CAST (_))
+
 /* Buffers received packets of type APPLICATION DATA and
  * HANDSHAKE DATA.
  */
@@ -265,7 +267,8 @@ _gnutls_read (gnutls_session_t session, 
     {
 
       if (session->internals._gnutls_pull_func == NULL)
-	i = recv ((int) fd, &ptr[sizeOfPtr - left], left, flags);
+	i = recv (GNUTLS_POINTER_TO_INT(fd), &ptr[sizeOfPtr - left],
+		  left, flags);
       else
 	i = session->internals._gnutls_pull_func (fd,
 						  &ptr[sizeOfPtr -
@@ -701,7 +704,7 @@ _gnutls_io_write_buffered (gnutls_sessio
     {
 
       if (session->internals._gnutls_push_func == NULL)
-	i = send ((int) fd, &ptr[n - left], left, 0);
+	i = send (GNUTLS_POINTER_TO_INT(fd), &ptr[n - left], left, 0);
       else
 	i = session->internals._gnutls_push_func (fd, &ptr[n - left], left);
 




More information about the Gnutls-devel mailing list