Back Tracking a Bad Line of Code - Need Help with Outputting to Find It
I have to back track through C code of a DLL that I didn't write to find why my C# application executes fine the first time, but then gets garbled results the second time. I have tracked it down to this function:
Code:
static GrowListEntry BZNA_GetBest(BecStruct *bzs)
{
int i;
int MaxI, MaxScore;
GrowListEntry RetVal;
MaxScore = -1;
for (i = 0; i < bzs->GrowListCount; i++)
{
if (bzs->GrowList[i].Score > MaxScore)
{
MaxI = i;
MaxScore = bzs->GrowList[i].Score;
/* MaxScore is the first variable that differs on second run */
ti_record_time("MaxScore %i", MaxScore);
}
}
/* hang on to best */
RetVal = bzs->GrowList[MaxI];
/* move last slot to emptying best slot and decrement count */
bzs->GrowList[MaxI] = bzs->GrowList[--bzs->GrowListCount];
return RetVal;
}
MaxScore is the first variable that differs on the second run, so I need to find a way to find out what is getting messed up before that in order to find the line of code that is really causing the problem. I guess I need to find a way to output something in the line of code: bzs->GrowList[i].Score > MaxScore and go from there to find the needle in the haystack.
I'm not use to C, so I don't know exactly the way to do this. Currently, I have been using the function ti_record_time() to output variables to the screen and then it is outputted to a text file so I can compare the first run to the second run. However, I don't know what I need to output this time. Any help is appreciated. And here's more of the C code that is relevant:
Code:
typedef struct tag_GrowListEntry
{
unsigned short Score;
signed char X;
signed char Y;
} GrowListEntry;
typedef struct tag_BecStruct
{
GrowListEntry GrowList[2851];
int GrowListCount;
} BecStruct;