Solved

_strnset behaving differently while executing in release mode

Posted on 2013-05-30
2
186 Views
Last Modified: 2013-10-23
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.
0
Comment
Question by:HarishMinu
2 Comments
 
LVL 8

Accepted Solution

by:
Subrat (C++ windows/Linux) earned 500 total points
ID: 39212345
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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now