coin-or / CoinUtils

COIN-OR Utilities
Other
44 stars 40 forks source link

CoinMessageHandler fails under 64-bit Microsoft C++ #86

Closed svigerske closed 5 years ago

svigerske commented 5 years ago

Issue created by migration from Trac.

Original creator: wxBen

Original creation time: 2014-12-13 00:05:01

Version:

In CoinMessageHandler.cpp, there are three instance of code that uses "long offset" as in:

long int offset = temp - (char *) rhs.message_;

Visual C++ 64-bit treats "long int" as four bytes, but pointers are eight bytes of course. Stupid, I know. But it makes it crash. So my quick fox for this is as follows:

#ifdef _WIN64
    __int64 offset = temp - (char *) rhs.message_;
#else
    long int offset = temp - (char *) rhs.message_;
#endif

So my request is, please fix the three instances in this file to be more portable. Perhaps rather than test for _WIN64 which may be MS specific, you can use size_t (which is eight bytes under 64-bit VSS). Or rewrite that code to not do pointer arithmetic using longs.

This is sadly a problem that plagues a lot of software, so sqlite for example, has a header file that tests and defines types accordingly, for example:

#if defined(_MSC_VER) || defined(__BORLANDC__)
  typedef __int64 sqlite_int64;
  typedef unsigned __int64 sqlite_uint64;
#else
  typedef long long int sqlite_int64;
  typedef unsigned long long int sqlite_uint64;
#endif
typedef sqlite_int64 sqlite3_int64;
typedef sqlite_uint64 sqlite3_uint64;
svigerske commented 5 years ago

Comment by @tkralphs created at 2015-01-06 19:06:44

This implementation seems to be from an old version of CoinUtils. I can't discern which one. The current version has a different implementation, which looks to me like it shoud work.

std::ptrdiff_t offset = temp - reinterpret_cast<char *> (rhs.message_);

svigerske commented 5 years ago

Comment by @tkralphs created at 2015-01-06 19:06:44

Resolution: invalid