Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

WX code bug due to integer casting

lincoder
2007-04-29
2013-04-17
  • lincoder
    lincoder
    2007-04-29

    Hi,

    When compiling of the wxwaste code, it fails with a load of errors similar to the following (for serval source files). NB sorry if this bug has been noted and fixed already

    In file included from platform.hpp:28,
                     from main.hpp:26,
                     from sharedmain.cpp:84:
    config.h:162:1: warning: this is the location of the previous definition
    sharedmain.cpp: In function 'void main_MsgCallback(T_Message*, C_MessageQueueList*, C_Connection*)':
    sharedmain.cpp:706: error: cast from 'char*' to 'int' loses precision
    sharedmain.cpp:726: error: cast from 'char*' to 'int' loses precision
    sharedmain.cpp:765: error: cast from 'char*' to 'int' loses precision
    sharedmain.cpp:820: error: cast from 'XferSend*' to 'int' loses precision
    make[1]: *** [sharedmain.o] Error 1
    make[1]: Leaving directory `/home/ben/waste'
    make: *** [all] Error 2

    The solution is to cast to value of type `long' instead of type int.

    My machine:

    Linux localhost 2.6.18-gentoo-r3 #10 SMP PREEMPT Tue Dec 12 15:29:39 GMT 2006 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 4200+ AuthenticAMD GNU/Linux
    gcc (GCC) 4.1.1 (Gentoo 4.1.1-r3)

    Lincoder

     
    • niere
      niere
      2007-04-30

      Yeah, these char* to int casts look like ugly hacks in the source code to begin with...

      We have (in itemlist.hpp):

      template<class T> class C_ItemList {
      // ...
      T *Get(int index);
      // ...
      }

      It's used as

      C_ItemList<char> g_uploads

      (in xferwnd.hpp) so there's the char* from the cast.

      In class W_ListView (in listview.hpp) there's the method

      int FindItemByParam(int param);

      and this param is the cast char* (that is: (int)g_uploads.Get(...)).

      Perhaps we should add a new method to either C_ItemList or W_ListView, with the right signature; if we need an int here, we should get it properly.
      Unfortunately I couldn't (yet) figure what FindItemByParam(int) does...

      niere