473,836 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Damage after block..." on deleting a char* (VS2003)

I have a doc/view app w/ a CRichEditView. In it, I define:
void CSyntaxView::Pa rseLine(long lineNum);

This function starts off by getting the text of the specified line (into a
CString):

CRichEditCtrl* ctrl = &GetRichEditCtr l();
int lineLen = ctrl->LineLength(lin eNum);
char* buf = new char[lineLen];
ctrl->GetLine(lineNu m, buf, lineLen);
CString line = buf;
line = line.Left(lineL en);
delete[] buf; ** Problem
buf = NULL;

However, when running in debug, I get an error on the delete line:
DAMAGE: after Normal block (#222) at 0x00337EF0.

I have tried using both delete[] and just delete and I get the error either
way. What am I doing wrong here???

If it would help here, is there an easier way to get the specified line into
a CString?

--
Adam Clauss
ca*****@tamu.ed u
Nov 16 '05 #1
1 2394
Hmm... I ended up reading that after I posted this.
Whats odd is that four wasn't the magic number. Tried it with + 4 to the
buffer and it still happened.

I haven't yet found which number it starts working for - but I kind of
randomly tested + 20 and it worked ;)

I'll go through and figure out what the cutoff number is.

--
Adam Clauss
ca*****@tamu.ed u
"David Lowndes" <da****@mvps.or g> wrote in message
news:l9******** *************** *********@4ax.c om...
CRichEditCtrl* ctrl = &GetRichEditCtr l();
int lineLen = ctrl->LineLength(lin eNum);
char* buf = new char[lineLen];
ctrl->GetLine(lineNu m, buf, lineLen);
CString line = buf;
line = line.Left(lineL en);
delete[] buf; ** Problem
buf = NULL;

However, when running in debug, I get an error on the delete line:
DAMAGE: after Normal block (#222) at 0x00337EF0.


Adam,

I think you need to consider this part of the documentation:

"Remarks
The copied line does not contain a terminating null character.

Note Because the first word of the buffer stores the number of
characters to be copied, make sure that your buffer is at least 4
bytes long.
"

...so try increasing the new'ed buffer by 4 bytes and see if that
prevents the memory error.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq

Nov 16 '05 #2

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

Similar topics

2
4277
by: Tim Hochberg | last post by:
During the recent, massive, painful Lisp-Python crossposting thread the evils of Python's whitespace based indentation were once again brought to light. Since Python' syntax is so incredibly brittle, and failure prone, it's amazing that we don't have more editor support for our feeble minds. To help reduce the severity of this crisis, I decided to take a whack at creating smart block copy and paste functionality. Anyway, I wrote some...
1
2655
by: terrencel | last post by:
I was told to look at some old C code that was ported to C++. One of the file is like: ========================================= CPPClass* someCPPVar = NULL; extern "C" {
3
1804
by: Castal | last post by:
hello, i am trying to learn javascript. i found an example of an menu, but there is one thing i do not understand. in the source it says: ' if(thisMenu.display == "block"){......' i do not understand what 'block' means.
32
4170
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:" sections in a "foreach" block The problem: The foreach statement allows iterating over all the...
0
994
by: Framework fan | last post by:
Hello. I am having difficulty testing when the user selects "Block all cookies" inside IE. My trouble is that my test cookie never gets blocked. I set IE's privacy level to "Block all cookies" I set IE's Local Intranet security setting to High.
1
4749
by: tankbattle | last post by:
That is, what's the difference between <complexType name="Address" final="restriction"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element name="city" type="string"/> </sequence> </complexType> and <complexType name="Address" block="restriction">
1
1757
by: kpr2009 | last post by:
How to achieve block selection effect in winforms, Richtextbox. Block selection: 1. Open a MS word document and type few lines. 2. Keep the cursor at middle of the first line 3. Press ALT + drag mouse seleciton of text is block level (vertical selection). Any code snnippet or pointer ? Googeled/MSDNed ...but no luck
0
9825
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9673
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10859
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10560
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6984
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.