12-01-2008 08:35 PM
Hello,
I write a program to control power supply. One of funtions is to set voltage and current in the table.
When i run it, it shows the below error message:
"Out-of-bounds pointer argument (past end of memory block)"
Could someone help me with this?
Thank you!
This function code is under below:
int CVICALLBACK SetValueCallBack (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
float Voltage_Set, Current_Set;
int TimeSet;
int RowSet;
char VoltageSetBuff[30];
char CurrentSetBuff[30];
case EVENT_COMMIT:
GetCtrlVal(panelHandle, PANEL_SETVOLTAGE, &Voltage_Set);
GetCtrlVal(panelHandle, PANEL_SETCURRENT, &Current_Set);
GetCtrlVal(panelHandle, PANEL_SETTIME, &TimeSet);
GetCtrlVal(panelHandle, PANEL_SETROW, &RowSet);
sprintf(VoltageSetBuff, "%2.2f", Voltage_Set);
sprintf(CurrentSetBuff, "%2.2f", Current_Set);
SetTableCellVal(panelHandle, PANEL_TABLE, MakePoint(1, RowSet), VoltageSetBuff);
SetTableCellVal(panelHandle, PANEL_TABLE, MakePoint(2, RowSet), CurrentSetBuff);
SetTableCellVal(panelHandle, PANEL_TABLE, MakePoint(3, RowSet), TimeSet);
break;
}
return 0;
}
Solved! Go to Solution.
12-01-2008 09:11 PM
12-02-2008 10:59 AM
I'm able to reproduce the issue, though I'm seeing the problem on the line just before the one you mention. I think this is likely because variables declared inside a switch statement before the case labels are not initialized the same way that other variables are.* If you move those variable declarations out before the switch, I think you'll find that your errors go away:
int CVICALLBACK SetValueCallBack (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
float Voltage_Set, Current_Set;
int TimeSet;
int RowSet;
char VoltageSetBuff[30];
char CurrentSetBuff[30];
switch (event)
{
case EVENT_COMMIT:
...
I'll file a bug report to make sure this gets further investigated.
* Note that by the C language rules, even an explicit initialization (e.g. int TimeSet = 10;) at that position inside the switch has no effect!
Mert A.
National Instruments
12-02-2008 06:23 PM
Thank you, Mert A.
11-05-2010 11:38 AM
How about at least a compiler warning stating "unreachable code"?