LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Disappearing variables

Odd one, this...

Function below loads an .ini file (attached). The stared line gives:
FATAL RUN-TIME ERROR: "Ana.c", line 81, col 21, thread id 0x000009A4: Dereference of out-of-bounds pointer: 1712154706 bytes (428038676 elements) before start of array.
If commented-out, the popup fires correctly, with card_count correctly incrementing from 0 to 3.

There is nothing else in this program - What am I doing wrong?


#define NUM_CHANNELS 32
#define CHANNELS_PER_ROUTER 8

short SPC_load(void)
{
char SPCtiming_Path[MAX_PATHNAME_LEN] = "c:\\data\\spc_timing.ini";

int SPC_fh;
float CFD_LimitLow[NUM_CHANNELS/CHANNELS_PER_ROUTER];
float CFD_ZeroCross[NUM_CHANNELS/CHANNELS_PER_ROUTER];
float Offset[NUM_CHANNELS/CHANNELS_PER_ROUTER];

char strLine[100], strVal[10];
int intLinelen, card_count = -1;
float fltVal;

SPC_fh = OpenFile (SPCtiming_Path, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII)

while ((intLinelen=ReadLine (SPC_fh, strLine, -1))>-1)
{
if ( (intLinelen>3) && !(strLine[0]==*";") )
{
StringLowerCase(strLine);
if (strstr (strLine, "spc"))
{
card_count++;
}

if (strstr (strLine, "cfd_ll"))
{
CopyString(strVal,0,strLine,7,-1);
fltVal = ceil(100 * atof(strVal))/100;
CFD_LimitLow[card_count] = fltVal;
}

if (strstr (strLine, "cfd_zc"))
{
CopyString(strVal,0,strLine,7,-1);
fltVal = ceil(100 * atof(strVal))/100;
******* CFD_ZeroCross[card_count] = fltVal; *******
sprintf(strLine,"%d",card_count);
MessagePopup("Error",strLine);
}

if (strstr (strLine, "tac_off"))
{
CopyString(strVal,0,strLine,8,-1);
fltVal = ceil(100 * atof(strVal))/100;
Offset[card_count] = fltVal;
}
}
}
CloseFile (SPC_fh);
return 0;
}

Message Edited by Pythonist on 05-25-2006 09:22 AM

Message Edited by Pythonist on 05-25-2006 09:22 AM

__________________________________________
The world is full of exciting challenges,
brilliantly disguised as insoluble problems.
0 Kudos
Message 1 of 4
(3,253 Views)
Commenting out the stared line (and following 2 lines), and adding:
CFD_ZeroCross[0] = 1;
before it creates the same error!  How can the indice be lost if it's constant?

__________________________________________
The world is full of exciting challenges,
brilliantly disguised as insoluble problems.
0 Kudos
Message 2 of 4
(3,242 Views)
Pythonist:
 
Your problem is that the comments in your file are longer than 100 characters, you are using a 100 character buffer to store the lines, and you are not telling ReadLine the length of the buffer. This is causing the stack to get trashed and since some debugging information is stored on the stack, the debugger is getting confused.
 
To fix this, you should increase the size of strLine, and instead of passing -1 as the last parameter to ReadLine, pass  (sizeof(strLine) - 1).
 
Hope this helps,
 
-alex
0 Kudos
Message 3 of 4
(3,230 Views)
Thank you.  Blindingly obvious once someone points it out.
I'm quite surprised there's not a run-time error if the line length is exceed...

Cheers.

Message Edited by Pythonist on 05-26-2006 05:51 AM

__________________________________________
The world is full of exciting challenges,
brilliantly disguised as insoluble problems.
0 Kudos
Message 4 of 4
(3,205 Views)