LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

cvi 2013 sp1 bug?

Hello,

 

I have defined a structure in the program :

 

typedef struct

{

    char name[100];

    char ip_addr[65];

    ...;

}BATTERY_ALARM_STATE;

 

static BATTERY_ALARM_STATE gBatteryAlarmState;

 

 

void func()

{

...;

 

        snprintf(gBatteryAlarmState.ip_addr, sizeof(gBatteryAlarmState.ip_addr), "%s", "127.0.0.1");
        snprintf(gBatteryAlarmState.name, sizeof(gBatteryAlarmState.name), "%s", "123456");

}

when executing the func(), it always popup the error message:  Attempt to write beyond end of string.  and the error always be stopped at the second "snprintf". This code run well in the cvi2013, but just have the error in the cvi 2013 sp1.

 

David

 

 

0 Kudos
Message 1 of 5
(4,735 Views)

A bit strange.

Try  snprintf(gBatteryAlarmState.name, sizeof(gBatteryAlarmState.name), "%s", "1");

Will it  popup the error message?

0 Kudos
Message 2 of 5
(4,715 Views)

yes, it also popup the error. if add a dummy string array in the structure, then access the name array element, the error will disappeared.

0 Kudos
Message 3 of 5
(4,692 Views)

So no any idea, I have to use the strncpy() instead of that.

0 Kudos
Message 4 of 5
(4,691 Views)

Hi David,

 

Where do you call func, in your program? I tried putting together a simple application (see snippet that follows), but it doesn't reproduce the behavior you described in LabWindows/CVI 2013 SP1.

 

// Include files

#include <ansi_c.h>

//====================================================================================================
// Types

typedef struct {
	char name[100];
	char ip_addr[65];
}BATTERY_ALARM_STATE;

//====================================================================================================
// Static global variables

static BATTERY_ALARM_STATE gBatteryAlarmState;

//====================================================================================================
// Function declarations

void func();

//====================================================================================================
// Global functions

int main ()
{
	func();
	return 0;
}

void func()
{
	snprintf(gBatteryAlarmState.ip_addr, sizeof(gBatteryAlarmState.ip_addr), "%s", "127.0.0.1");
	snprintf(gBatteryAlarmState.name, sizeof(gBatteryAlarmState.name), "%s", "123456");
}

//====================================================================================================

 

Can you confirm whether this code causes the same error for you?

 

Thanks,

Daniel Dorroh
National Instruments
0 Kudos
Message 5 of 5
(4,672 Views)