I'm using a map to merge duplicates and sort items in a dll. It's not exposed in the interface of the dll. The simplified code is as follows.
UINT GetInfo(UINT request, LPVOID data)
{
//...
switch (request)
{
case COUNT_RES:
{
CountRes* countRes = (CountRes*)data;
ZeroMemory(countRes, sizeof(CountRes));
try
{
//...
PUINT posValue = (PUINT)buffer;
PUINT posCount = (PUINT)buffer2;
FLOAT value; UINT count;
std::map<FLOAT, UINT, std::greater<FLOAT> > coinMap; //Access violation
countRes->rejected = ntohl(posCount[20]);
for (UCHAR i = 0; i < 20; ++i)
{
value = (FLOAT)ntohl(posValue[i]) / 100;
count = ntohl(posCount[i]);
coinMap[value] += count; //Access violation
countRes->total += value * count;
}
//...
}
//...
}
The GetInfo function is called from an exe. The showed code raises an access violation exception at the declaration line. The call stack is as follows.
_heap_alloc_dbg(unsigned int 0x00000018, int 0x00000001, const char * 0x00000000, int 0x00000000) line 394 + 8 bytes
_nh_malloc_dbg(unsigned int 0x00000018, int 0x00000001, int 0x00000001, const char * 0x00000000, int 0x00000000) line 242 + 21 bytes
_nh_malloc(unsigned int 0x00000018, int 0x00000001) line 194 + 19 bytes
operator new(unsigned int 0x00000018) line 24 + 11 bytes
std::_Allocate(int 0x00000018, char * 0x00000000) line 30 + 9 bytes
std::allocator<unsigned int>::_Charalloc(unsigned int 0x00000018) line 62 + 11 bytes
std::_Tree<float,std::pair<float const ,unsigned int>,std::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >::_Kfn,std::greater<float>,std::allocator<unsigned int> >::_Buynode(...) line 587 + 10 bytes
std::_Tree<float,std::pair<float const ,unsigned int>,std::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >::_Kfn,std::greater<float>,std::allocator<unsigned int> >::_Init() line 461 + 16 bytes
std::_Tree<float,std::pair<float const ,unsigned int>,std::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >::_Kfn,std::greater<float>,std::allocator<unsigned int> >::_Tree<float,std::pair<float const ,unsigned int>,std::ma1aad805f(const std::greater<float> & {...}, unsigned char 0x00, const std::allocator<unsigned int> & {...}) line 162 + 67 bytes
std::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >(const std::greater<float> & {...}, const std::allocator<unsigned int> & {...}) line 57 + 47 bytes
GetInfo(unsigned int 0xffffffff, void * 0x0012f658) line 331 + 25 bytes
If I declare coinMap
out of the try
scope, then the exception occurs at the insertion line instead. The call stack is as follows.
std::greater<float>::operator()(const float & 1.00000, const float &) line 80 + 37 bytes
std::_Tree<float,std::pair<float const ,unsigned int>,std::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >::_Kfn,std::greater<float>,std::allocator<unsigned int> >::insert(const std::pair<float const ,unsigned int> & {...}) line 222 + 37 bytes
std::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >::insert(const std::pair<float const ,unsigned int> & {...}) line 96 + 45 bytes
std::map<float,unsigned int,std::greater<float>,std::allocator<unsigned int> >::operator[](const float & 1.00000) line 93 + 65 bytes
GetInfo(unsigned int 0xffffffff, void * 0x0012f658) line 337 + 18 bytes
I have no clue how to solve the issue. Please help!
Crash in legal allocation code is 99.99% heap corruption issue.
Comment out all data
/ countRes
references in GetInfo()
and see is crash still raising. If yes very likely the problem is outside of code you posted here.
User contributions licensed under CC BY-SA 3.0