[Bug report] for NCollection_IncAllocator on Windows 64 bit

Microsoft's Visual C++ compiler uses the LLP64 model. So the pointer size is 8 bytes and long int is only 4 bytes.
The type cast to (unsigned long) in line 15 of NCollection_IncAllocator.cxx

#define IMEM_ALIGN(_addr) (sizeof(aligned_t)* IMEM_SIZE((unsigned long)(_addr)))

therefore truncates the address (_addr) to 4 bytes (at least on Windows platforms).
If a new allocated block has an address returned by malloc exceeding 4 bytes this results in a wrong pointer returned by NCollection_IncAllocator::allocateNewBlock and NCollection_IncAllocator::Allocate. This can cause an access violation in the following.
I figured this out when I received some access violation crashes during meshing.

As a fix I suggest casting to size_t instead:

#define IMEM_ALIGN(_addr) (sizeof(aligned_t)* IMEM_SIZE((size_t)(_addr)))

sergey zaritchny's picture

Hi Markus,
I would like to inform you that the posted problem is checked and the corresponding issue with ID = OCC22293 has been registered.
Later you can know if the issue is resolved by checking references to the specified ID in OCCT Release Notes. The analysis of the issue (to find the most effective solution) will take some time depending on our technical capability and availability of resources.
Thanks for you contribution.

Regards