08-13-2014 04:30 PM
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
08-14-2014 02:21 PM
Thanks for pointing this out, I'll go ahead and file a Corrective Action Request on this.
12-11-2014 05:20 PM
We are tracking this issue with bug ID: 487428, for your records.