473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need urgent help.

Hello,

I am running the following code segment in visual studio 2005.

size_t cchSize = 10*sizeof(TCHAR);
LPTSTR temp = (LPTSTR)malloc(cchSize);
temp[0] = '\0';
_tcscat_s(temp, cchSize, _T("hello"));
free(temp);

It fails at the statement -

free(temp)

with the error:

Heap block at 00A57F80 modified at 00A57FC0 past requested size of 38.

If i change _tcscat_s to deprecated _tcscat there is no error. Can
anyone throw some light on this?
Thanks,
C++Programmer.

Mar 28 '06 #1
4 4407
dr******@yahoo.com wrote:
Hello,

I am running the following code segment in visual studio 2005.

size_t cchSize = 10*sizeof(TCHAR);
LPTSTR temp = (LPTSTR)malloc(cchSize);
temp[0] = '\0';
_tcscat_s(temp, cchSize, _T("hello"));
free(temp);

It fails at the statement -

free(temp)

with the error:

Heap block at 00A57F80 modified at 00A57FC0 past requested size of 38.

If i change _tcscat_s to deprecated _tcscat there is no error. Can
anyone throw some light on this?


Not really, those functions starting with an underscore do not exist in
C++ and I have no idea what they do. Perhaps you should ask in a
newsgroup where those functions are topical, perhaps one with microsoft
and windows in the name.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 28 '06 #2
In article <11**********************@e56g2000cwe.googlegroups .com>,
"dr******@yahoo.com" <dr******@yahoo.com> wrote:
Hello,

I am running the following code segment in visual studio 2005.

size_t cchSize = 10*sizeof(TCHAR);
LPTSTR temp = (LPTSTR)malloc(cchSize);
temp[0] = '\0';
_tcscat_s(temp, cchSize, _T("hello"));
free(temp);

It fails at the statement -

free(temp)

with the error:

Heap block at 00A57F80 modified at 00A57FC0 past requested size of 38.

If i change _tcscat_s to deprecated _tcscat there is no error. Can
anyone throw some light on this?


I believe that if you put the above code in a main all by itself, the
error will go away as well. If not, then probably _tcscat_s doesn't do
what you think it does and is writing past the requested size.

I can't help but wonder how big a TCHAR is if 10 * sizeof(TCHAR) ends up
equaling 38...
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Mar 28 '06 #3
drazbliz wrote:
I am running the following code segment in visual studio 2005.

size_t cchSize = 10*sizeof(TCHAR);
LPTSTR temp = (LPTSTR)malloc(cchSize);
temp[0] = '\0';
_tcscat_s(temp, cchSize, _T("hello"));
free(temp);


Why on Earth are you not using a CString, a CStringW, or a _bstr_t?

And why are you using a strcat() derived method when you could use a
strcpy() derived method, or even a _tcsdup()?

And why malloc() in a C++ program?

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Mar 28 '06 #4
Hello,

I am running the following code segment in visual studio 2005.

size_t cchSize = 10*sizeof(TCHAR);
LPTSTR temp = (LPTSTR)malloc(cchSize);
temp[0] = '\0';
_tcscat_s(temp, cchSize, _T("hello"));
free(temp);

It fails at the statement -

free(temp)

with the error:

Heap block at 00A57F80 modified at 00A57FC0 past requested size of 38.

If i change _tcscat_s to deprecated _tcscat there is no error. Can
anyone throw some light on this?
_tcscat_s (and most if not all the secure runtime functions) uses the # of characters as the buffer size, not the # of bytes. You're probably compiling using the Unicode character set, so a TCHAR is 2 bytes, not 1.

The debug version of these functions also write to the entire buffer area, so by telling it there's 20 characters (40 bytes), the _tcscat_s function ends up overwriting memory beyond the allocated 10 characters (20 bytes), which leaves the heap damaged.


Try:

size_t cchSize = 10;
LPTSTR temp = (LPTSTR)malloc(cchSize*sizeof(TCHAR));
temp[0] = '\0';
_tcscat_s(temp, cchSize, _T("hello"));
free(temp);
May 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jenny | last post by:
Need urgent help for an unsolved problem. In our ASP web application, we creat a Back button and if user click on this button, it execute history.go(-1) to go back to the previous page. All our...
3
by: Rahul S. | last post by:
Hey all: I need urgent information how to set the environment in Visual.NET wiritng in C. I am working with a licensed version of the Analyze 6.0 software from mayo clinic. I need to write...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
2
by: Max Power | last post by:
Hi All I am coding a small app in that swaps specific files between a client and server. All files and locations are set at both sides. I want my app to show a file list, based on the file...
1
by: TexCube | last post by:
Hello everyone, I have an urgent question. Can data be pulled from an access database table to create a directory that can be printed out and bound together? I need to have each row of a...
10
by: David Thielen | last post by:
Hi; I have help html pages for each page of my ASP.NET webapp. So for the page datasource.aspx, I have help\datasource.htm. Bu what I want when the hyperlink is clicked, for it to look for the...
0
by: sanjayhire | last post by:
Hi All, I have just joined the forum. I need your help..As it's very urgent... How to identify a particular process is running on a server(Windows/Unix server) using VB program and since how...
1
by: psantosh12 | last post by:
Hello Frnds Please need help to resolve error.......... it is very very urgent........ The error is Runtime Error Description: An application error occurred on the server. The current custom...
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.