tags:

views:

113

answers:

2

Hi,

When I try to debug the following function segment, the execution brakes (jumps out of the function) at line pCellTower->m_pCellTowerInfo = pCellInfo:

RILCELLTOWERINFO* pCellInfo = (RILCELLTOWERINFO*)lpData;

CCellTower *pCellTower = (CCellTower*)cbData;
if(pCellTower != NULL)
{
    pCellTower->m_pCellTowerInfo = pCellInfo;
}

(the pointer pCellInfo is not set)

Then I tried to comment the line:

RILCELLTOWERINFO* pCellInfo = (RILCELLTOWERINFO*)lpData;

CCellTower *pCellTower = (CCellTower*)cbData;
if(pCellTower != NULL)
{
    //pCellTower->m_pCellTowerInfo = pCellInfo;
}

and this way the function executes normally.

Does anyone know what could be wrong?

+2  A: 

The most likely explanation is that pCellTower isn't set either. It could contain random bits, and end up pointing outside the memory allocated to your app. The OS cannot allow your program to write outside the space allocated to it, so it sends the program some kind of message (Windows:exception, Unix/Linux:signal) that the write was rejected.

MSalters
A: 

If you trace backwards where the cbData value originates from, you'll probably find it is an uninitialized, random value.

Paul Dixon