_strnset behaving differently while executing in release mode

Hello Experts

Following is the code which appends spaces to a CString.
		long l_no_of_chars = 100;
		LPSTR t_space_text = NULL;
		CString u_space;

		//	Allocate that much space
		t_space_text = (LPSTR) malloc (l_no_of_chars + 1);
		//	Fill the variable with 32
		_strnset( t_space_text, 32, l_no_of_chars);	
		//	Set the Last Character
		*(t_space_text + l_no_of_chars) = 0;
		//	Get the Left Text
		u_space = t_space_text;
		::MessageBox (NULL,"File", u_space, MB_OK | MB_ICONINFORMATION);

		//	Free allocated memory
		free (t_space_text);

Open in new window

When I excute in release mode MessageBox is not displaying spaces  and when I debug in the release mode it is showing.

Please help in getting resolved, Thanks in advance.
HarishMinuAsked:
Who is Participating?
 
Subrat (C++ windows/Linux)Connect With a Mentor Software EngineerCommented:
Try using safer version _strnset_s instead of _strnset(Deprecated One).
I hope in release ver. due to code optimization, it might be truncating spaces...
0
All Courses

From novice to tech pro — start learning today.