I have found a lot of answers that have to do with release version problems but none with the exact opposite.
I have a loop similar to the following:
while(index < 7 && FlagIsUp)
{
// process
Inner Loop
Inner Inner Loop
Array[index] = number;
++index;
}
Problem is that index changes radically from 6 (the last iteration) to 17209 for an int16_t and 1133165442 for size_t. NOTHING IN THE LOOP changes the index except the ++index. I replaced the while with a for and it still happens.
It only happens in debug mode, in release version it does finish without issues.
I also added volatile to the index and results were the same, it still overflowed.
Any ideas, pointers, would be appreciated. I can't provide a working copy of the bug so any theories are welcomed, I want to exhaust my options to find the problem.
EDIT: Yes I'm sorry. I gave to little information. First off I'm working with QNX Momentics Version: 4.6.0 and my debugger is part of the GNU Compiler Collection 4.3.3.
Now the inner loop is this:
cSignalNoIndex = 0;
while ((cSignalNoIndex < (2 * NO_PHASES + 1)) && !ShutDownFlag)
{
wSF0 = 0;
wExtSF = 0;
dwSFAcc = 0;
dwExtSFAcc = 0;
std::string SignalNo= " Waveform number " + Tool::toString(cSignalNoIndex);
Results[cSignalNoIndex].printWaveForm(SignalNo);
// Prepare Input vectors for FFT compute
cComponent = 0;
while (cComponent < (HCYCLE_SAMPLES << 1))
{
awReal[cComponent] = static_cast<int>(Results[cSignalNoIndex].WaveForm[cComponent/64][cComponent % 64]);
awImg[cComponent] = 0;
pwSource++;
cComponent++;
}
Results[cSignalNoIndex].printWaveForm(SignalNo);
// Get FFT (forward)
// Changed the wPwr from 7 to something else
iFft(&awReal[0], &awImg[0], wPwr, 1);
Results[cSignalNoIndex].printWaveForm(SignalNo);
// Compute magnitudes
//fMult = pInBlock3->fMult[cSignalNoIndex]; // Get Multiplier
fMult = 1;
for (cComponent = 0; cComponent < HCYCLE_SAMPLES && !ShutDownFlag; cComponent++)
{
int64_t dlOp = static_cast<int64_t>(awReal[cComponent]) * awReal[cComponent] + static_cast<int64_t>(awImg[cComponent]) * awImg[cComponent];
dlOp <<= 1; // Apply sqrt(2) term to result
dlOp = static_cast<int>(fMult * isqrt64(dlOp));
// Store into FFT object
oFFTMag3.wFFT[cSignalNoIndex][cComponent] = static_cast<int16_t>( dlOp );
// Set Base frequency magnitude and accumulate harmonics
if (cComponent == 1) // Base
{
wSF0 = dlOp;
if(cSignalNoIndex == 6)
{
wRefMagnitude = static_cast<int16_t> ( 0.4 * wSF0 );
}
if(awReal[1] != 0) // Also get phase for Base
{
dfPhase = std::atan((double)((float)awImg[1]/awReal[1])) * 180.0 / PI;
}
else
{
if(awImg[1] >= 0)
{
dfPhase = 90.0;
}
else
{
dfPhase = -90.0;
}
}
if(awReal[1] < 0) // convert to 2*PI range
{
dfPhase += 180.0;
}
else if(awImg[1] < 0)
{
dfPhase += 360.0;
}
//// THIS IS THE LINE
fPhase[cSignalNoIndex] = dfPhase; ////////// WTF! cSignalNoIndex = 6 - cComponent = 2
/// HERE cSignalNoIndex is overflown
}
}