LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible CVI13 Debug Mode Bug

I have found a possible bug in Debug mode in CVI13.  The issue is a bit complicated.  It has to do with returning a struct from a function, then referencing a char pointer in that struct in a call to sprintf.  The basic code is:

 

struct TEST_STRUCT
{
    char *StructString;
} TestStruct = 
{
    {
        "Struct String"
    },
};

struct TEST_STRUCT TestFunction(void)
{
    return TestStruct;
}

// somewhere in the code...
    sprintf(Buff, "%s", TestFunction().StructString);

 

When executed in Debug mode, the sprintf line generates the runtime warning, "Attempt to read beyond end of string".  If you select Continue the string in Buff is incorrect.  If you run the same program in Release mode it works as expected.  I found this when trying to debug a project previously built in CVI 12.  CVI 12 does not generate this warning.  I also tried refercing the string directly in CVI 13:

 

    sprintf(Buff, "%s", TestStruct.StructString);

 This works correctly.  I also tried using an array in the struct instead of a pointer:

 

struct TEST_STRUCT
{
    char StructString[50];
} TestStruct = 
{
    {
        "Struct String"
    },
};

 

This also works correctly.  I also tried using strcpy instead of sprintf:

 

    strcpy(Buff, TestFunction().StructString);

 

This also works correctly.  The issue appears to be specific to returning a struct and then referecing a char pointer in that struct as a parameter to sprintf.

 

A sample project is attached.

 

Tony G

0 Kudos
Message 1 of 3
(4,669 Views)

Thanks for pointing this out, I'll go ahead and file a Corrective Action Request on this.

Rob S
Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(4,645 Views)

We are tracking this issue with bug ID: 487428, for your records.

Daniel Dorroh
National Instruments
0 Kudos
Message 3 of 3
(4,147 Views)