[Symphony-tickets] [SYMPHONY] #55: Incorrect cast for 64 bit?

SYMPHONY coin-trac at coin-or.org
Tue Feb 19 15:57:55 EST 2008


#55: Incorrect cast for 64 bit?
----------------------+-----------------------------------------------------
  Reporter:  fmargot  |       Owner:  tkr             
      Type:  defect   |      Status:  assigned        
  Priority:  normal   |   Milestone:  5.2             
 Component:  VRP      |     Version:  stable/5.1 (SVN)
Resolution:           |    Keywords:                  
----------------------+-----------------------------------------------------
Comment (by pbelotti):

 The problem is a cast of a 64bit address to a 32bit (?) integer. Pointer
 arithmetics on 64bit machines is a bit tricky... I could replicate the
 problem on an Opteron machine and solved it with pointer type uintptr_t.
 Try changing that line from

     pos = ((int)ed0 - (int)g->edges)/sizeof(edge_data) + 1;

 to

     pos = ((uintptr_t)ed0 - (uintptr_t)g->edges)/sizeof(edge_data) + 1;

 and adding

 #include <inttypes.h>

 at the beginning. I attach a svn diff below. I did not test the VRP
 application though.

 {{{
 $ svn diff
 ../../../../SYMPHONY/Applications/VRP/src/Master/vrp_master_functions.c
 Index:
 ../../../../SYMPHONY/Applications/VRP/src/Master/vrp_master_functions.c
 ===================================================================
 ---
 ../../../../SYMPHONY/Applications/VRP/src/Master/vrp_master_functions.c
 (revision 1292)
 +++
 ../../../../SYMPHONY/Applications/VRP/src/Master/vrp_master_functions.c
 (working copy)
 @@ -18,6 +18,7 @@
  #include <unistd.h>
  #endif
  #include <stdio.h>
 +#include <inttypes.h>
  #include <stdlib.h>
  #include <stddef.h>
  #include <string.h>
 @@ -55,7 +56,7 @@
          (void)memcpy((char *)ed0, (char *)ed1, sizeof(edge_data));
        }
     }
 -   pos = ((int)ed0 - (int)g->edges)/sizeof(edge_data) + 1;
 +   pos = ((uintptr_t)ed0 - (uintptr_t)g->edges)/sizeof(edge_data) + 1;
     g->allocated_edgenum -= g->edgenum - pos;
     if (alloc_old){
        g->edges = (edge_data *) realloc
 }}}

-- 
Ticket URL: <https://projects.coin-or.org/SYMPHONY/ticket/55#comment:3>
SYMPHONY <http://projects.coin-or.org/SYMPHONY>
The SYMPHONY framework for parallel branch-and-cut algorithms.



More information about the Symphony-tickets mailing list