LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Out-of-bounds pointer argument (past end of memory block)

Solved!
Go to solution

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;
}

 

0 Kudos
Message 1 of 5
(6,728 Views)
Sorry, I forget to say the error appears in "SetTableCellVal(panelHandle, PANEL_TABLE, MakePoint(2, RowSet), CurrentSetBuff);".  Thank you!
0 Kudos
Message 2 of 5
(6,725 Views)
Solution
Accepted by topic author a710756

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

Message 3 of 5
(6,691 Views)

Thank you, Mert A. 

 

0 Kudos
Message 4 of 5
(6,676 Views)

How about at least a  compiler warning stating "unreachable code"?

 

 

TestStand 4.2.1, LabVIEW 2009, LabWindows/CVI 2009
0 Kudos
Message 5 of 5
(5,982 Views)