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

Andreas Metzler ametzler at downhill.at.eu.org
Fri Jun 16 19:59:18 CEST 2006


On 2006-06-16 Simon Josefsson <jas at extundo.com> wrote:
> Andreas Metzler <ametzler at downhill.at.eu.org> writes:
>> building gnutls 1.4.0 (or 1.2.11) on a 64bit arch (amd64, ia64, ...)
>> triggers a couple of cast warnings:

> Thanks!  Patches to fix these problems are always appreciated.

This is out of my league, I just was pointed to these warning as
something that *might* be a real bug.

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

On my ix86 system the glib macros look like this
/usr/lib/glib-2.0/include/glibconfig.h
#define GPOINTER_TO_INT(p)      ((gint)   (p))
#define GINT_TO_POINTER(i)      ((gpointer)  (i))

However on alpha, ia64 and am64
#define GPOINTER_TO_INT(p)      ((gint)  (glong) (p))
#define GINT_TO_POINTER(i)     ((gpointer) (glong) (i))


With the respective types defined (identical on all four platforms) in
/usr/include/glib-2.0/glib/gtypes.h:
typedef void* gpointer;
typedef int    gint;
typedef long   glong;

The arch-dependend file is generated by ./configure.in using
-----------------------
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(void *)
[...]
case $ac_cv_sizeof_void_p in
$ac_cv_sizeof_int)      glib_gpi_cast=''        glib_gpui_cast=''         ;;
$ac_cv_sizeof_long)     glib_gpi_cast='(glong)' glib_gpui_cast='(gulong)' ;;
*)                      glib_unknown_void_p=yes ;;
esac
[...]
#define GPOINTER_TO_INT(p)      ((gint)  ${glib_gpi_cast} (p))
#define GPOINTER_TO_UINT(p)     ((guint) ${glib_gpui_cast} (p))

#define GINT_TO_POINTER(i)      ((gpointer) ${glib_gpi_cast} (i))
#define GUINT_TO_POINTER(u)     ((gpointer) ${glib_gpui_cast} (u))
------------------------

I guess gnutls would need to use a similar approach. FWIW I just ran a
short test, this patch
------------------
--- gnutls_buffers.c.orig       2006-06-16 17:50:33.000000000 +0000
+++ gnutls_buffers.c    2006-06-16 17:52:18.000000000 +0000
@@ -265,7 +265,7 @@
     {

       if (session->internals._gnutls_pull_func == NULL)
-       i = recv ((int) fd, &ptr[sizeOfPtr - left], left, flags);
+       i = recv ((int) (long) fd, &ptr[sizeOfPtr - left], left, flags);
       else
        i = session->internals._gnutls_pull_func (fd,
                                                  &ptr[sizeOfPtr -
@@ -701,7 +701,7 @@
     {

       if (session->internals._gnutls_push_func == NULL)
-       i = send ((int) fd, &ptr[n - left], left, 0);
+       i = send ((int) (long) fd, &ptr[n - left], left, 0);
       else
        i = session->internals._gnutls_push_func (fd, &ptr[n - left], left);
------------------
indeed gets rid of the two warnings for this file on ia64 (but breaks
on i386 of course).


> How large is 'int' on your platform?  How large is 'void*'?

According to ./configure in the respective buildlogs
http://buildd.debian.org/build.php?pkg=gnutls13

alpha, ia64, amd64
checking size of unsigned long... 8
checking size of unsigned int... 4
checking size of unsigned char*... 8

thanks, cu andreas
-- 
The 'Galactic Cleaning' policy undertaken by Emperor Zhark is a personal
vision of the emperor's, and its inclusion in this work does not constitute
tacit approval by the author or the publisher for any such projects,
howsoever undertaken.                                (c) Jasper Ffforde




More information about the Gnutls-devel mailing list