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

Szilard Pfeiffer szilard.pfeiffer at gmail.com
Wed Nov 19 14:35:35 CET 2008


Francis Brosnan Blazquez wrote:
> Hi Szilard,
>
>   
>> There is macro to convert integers to pointer value in libaxl 
>> (src/axl_config.h):
>>
>> #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.
>>     
>
> It's imposible to truncate an integer value as you describe since a
> integer (int) have always a 32 bits representation (in any arch), as
> long as I know.... 
>   
You are right, but I referred to the parameter of the INT_TO_PTR, when I 
wrote "integer value". Sorry for the ambiguous expression.
>   
>> Here is a test case:
>>
>> #include <axl.h>
>>
>> #include <stdio.h>
>>
>> int
>> main()
>> {
>>   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;
>> }
>>     
>
> In the same direction, you are passing a (long) variable to the
> INT_TO_PTR declaration. This is meant to be used with the (int) type not
> with (long).
>
>   
It is your choice.
>> 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 */
>>     
>
> However the real bug is here!!
>
> I can believe we have been running with this bug until now. The
> following code you are pointing mustn't use INT_TO_PTR over
> connection->channels because it is already a pointer!!
>
> That's why you are experimenting problems in amd64 because your
> connection->channels pointer is loosing its higher 32bits part.
>   
Yeah. That's the point.
> I've searched for similar declarations (using INT_TO_PTR) and I've found
> similar mistake one more time. 
>
> Thanks for reporting Szilard. Cheers!
>   



More information about the Vortex mailing list