[Vortex] wrong int to ptr conversion in case of 64 bit

Szilard Pfeiffer szilard.pfeiffer at gmail.com
Wed Nov 19 13:30:04 CET 2008

There is macro to convert integers to pointer value in libaxl 

#define INT_TO_PTR(integer)   ((axlPointer) (long) ((int)integer))

In case of amd64 architecture both the size of long and void * are 64 
bits, but the size of int is 32 bits, so the macro above truncates the 
higher 32 bits of the ineteger value.

Here is a test case:

#include <axl.h>

#include <stdio.h>

  printf("%ld %ld %ld\n", sizeof(int), sizeof(long), sizeof(void *));

  long l = 0x8765432112345678L;
  void *p = INT_TO_PTR(l);

  printf("0x%lx %p\n", l, p);

  void *p0 = &l;
  void *p1 = INT_TO_PTR(PTR_TO_INT(p0));

  printf("%p %p\n", p0, p1);
  return 0;

Possible solution:

--- configure.ac    (revision 3658)
+++ configure.ac    (working copy)
@@ -126,7 +126,7 @@
  * @return A \ref axlPointer reference.
-#define INT_TO_PTR(integer)   ((axlPointer) ${pti_cast} ((int)integer))
+#define INT_TO_PTR(integer)   ((axlPointer) ${pti_cast} (integer))
  * @brief Allows to convert a pointer reference (\ref axlPointer),

Patch above workarounds the following problem (which cause segmentation 
fault in amd64 architecture) in libvortex:

--- src/vortex_connection.c    (revision 3658)
+++ src/vortex_connection.c    (working copy)
@@ -3057,7 +3057,7 @@
     /* channel 0 always exists, and cannot be closed. It's closed
      * when connection (or session) is closed */
-    channel = vortex_hash_lookup (INT_TO_PTR (connection->channels), 
+    channel = vortex_hash_lookup (connection->channels, 
     if (channel == NULL)
         vortex_log (LOG_DOMAIN, VORTEX_LEVEL_DEBUG, "failed to get 
channel=%d", channel_num);

More information about the Vortex mailing list