I have a function such that one of its parameters is a 2D array of type int. The parameter is defined as follows:
[code]
int topoGraph [][MAX_VERTICES]
[\code]
However, the following code snippet from the body of the function crashes at the specified line:
[code]
if( counter >= 4 && !adjMatrixAlreadySet)
{
if( edgeCost == 10 )
{
topoGraph[srcVertex][dstVertex] = 1; <<<<<---------- The point of crash
}
else if( edgeCost == 100000 )//restricted link
{
topoGraph[srcVertex][dstVertex] = edgeCost;
}
else if( edgeCost == 300000 )//isolated link
{
topoGraph[srcVertex][dstVertex] = 0;
}
else{}
adjMatrixAlreadySet = true;
totalEdges++;
}
[\code]
It seems like there is an undefined behaviour at the specified point of crash since it crashes with different values of srcVertex and dstVertex each time I run it.
OK, so why not debug the function if this is how easy it is to duplicate the error? You told us it crashes on a line in the function, but why not debug the code to determine where things start going wrong? Start from the first line in the function, single step through it, and see at each step which variable(s) start to go off in the wrong direction, or which logic you've written will not work.
The line of code that crashes doesn't mean that is where the problem started. The problem started earlier, and you have to debug the code to figure this out.
Bookmarks