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

Home Posts Topics Members FAQ

DAMAGE: after Normal block (#45)

Hi all,

I just joined this group and am new to VC++. I wrote the code following
the next para in C++ and used VC++ 6.0 Enterprise Edition to build and
test.

I had the following error message because of an exception that gets
thrown when I call delete [] ipAddress; in the destructor -
~TrapDestinatio n () :

"DAMAGE: after Normal block (#45)"

// ~~~~~~~~~~~
// plugIn.h
// ~~~~~~~~~~~
#include <memory>
#include <iostream>
#include <exception>
#include <assert.h>
using namespace std;

typedef char* pchar;

class TrapDestination {
private:
pchar ipAddress;
int port;
pchar communityName;
int snmpVersion;
pchar templateFileNam e;
void (*old_unexpecte d) ();

public:
TrapDestination () : ipAddress (NULL), communityName (NULL),
templateFileNam e (NULL) { //old_unexpected =
set_unexpected( ::my_unexpected *);
}
~TrapDestinatio n () throw () {
cout << "TrapDestinatio n Destructor" << endl;
if (ipAddress)
delete [] ipAddress;
if (communityName)
delete [] communityName;
if (templateFileNa me)
delete [] templateFileNam e;

//set_unexpected( old_unexpecte*d ); // restore org
handler
if (uncaught_excep tion())
cout << "uncaught_excep tion() is TRUE" << endl;

else
cout << "uncaught_excep tion() is FALSE" <<
endl;
}

char *getIPAddress () throw () { return ipAddress; }
int getPort () throw () { return port; }
char *getcommunityNa me () throw () { return communityName; }
int getsnmpVersion () throw () { return snmpVersion; }
char *gettemplateFil eName () throw () { return
templateFileNam e; }

void setIPAddress (char *ipAddr="") throw () {
ipAddress = (pchar) new char(strlen (ipAddr) + 1);
if (ipAddress)
strcpy (ipAddress, ipAddr);
}

void setPort (int aPort=162) { port = aPort; }

void setcommunityNam e (char *aCommunityName ="public") {
communityName = (pchar) new char (strlen
(aCommunityName ) + 1);
if (communityName)
strcpy (communityName, aCommunityName) ;
}

void setsnmpVersion (int snmpVer=2) { snmpVersion = snmpVer; }

void settemplateFile Name (char *templFileName= "") {
templateFileNam e = (pchar) new char (strlen
(templFileName) + 1);
if (templateFileNa me)
strcpy (templateFileNa me, templFileName);
}
};

class SnmpTrapGen {
private:
char *ipAddress;
int port;
char *community;
int snmpVersion;
public:
SnmpTrapGen (char *ipAddress=NULL , int port=162, char
*community="pub lic", int snmpVersion=2){
}
~SnmpTrapGen () {
if (ipAddress)
delete [] ipAddress;
if (community)
delete [] community;
}

sendTrap (char *alertToSend);
char *getIPAddress () { return ipAddress; }
int getPort () { return port; }
char *getcommunity () { return community; }
int getsnmpVersion () { return snmpVersion; }

void setIPAddress (char *ipAddr="") {
ipAddress = new char (strlen (ipAddr) + 1);
if (ipAddress)
strcpy (ipAddress, ipAddr);
}
void setPort (int aPort=162) { port = aPort; }
void setcommunity (char *aCommunity="pu blic") {
community = new char (strlen (aCommunity) + 1);
if (community)
strcpy (community, aCommunity);
}
void setsnmpVersion (int snmpVer=2) { snmpVersion = snmpVer; }

};
// ~~~~~~~~~~~~
// plugIn.cpp
// ~~~~~~~~~~~~

#include "net-snmp\net-snmp-config.h"
#include "net-snmp\net-snmp-includes.h"
#include "plugIn.h"

void local_terminato r() {
cout << "terminate called local_terminato r !!!" << endl;
exit(1);
}

void (*old_terminate )();

void my_unexpected () {
// This cannot return - instead it can either call std::terminate( ) or
throw an exception

cout << "Am in my_unexpected " << endl;
}

int main (int argc, char **argv) {
try {
TrapDestination td;

old_terminate = set_terminate(l ocal_terminator *);
td.setIPAddress ("127.0.0.1" );
td.setcommunity Name ();
td.settemplateF ileName ("tempname") ;
cout << "IP address = " << td.getIPAddress () << endl;
printf ("communityN ame = %s.\n", td.getcommunity Name
());
printf ("templateFileN ame = %s.\n",
td.gettemplateF ileName ());
return 0;
} catch (bad_exception const &) {
printf("Caught bad_exception\n "); // though such an
exception was
never thrown
return 0;
} catch (...) {
cout << "Inside main's catch all" << endl;
return 0;
}
}
Any light on :

1. Why is delete causing this exception to be thrown could be helpful.
2. What the solution for this is.

will be great!

Just to add, an earlier post similar to this scenario had a response
that while allocating space for a string using new, make sure you add 1
for the '\0'. However I have taken care of doing that in my code and
yet I have this exception when it hits the delete.

I really need help from an expert.

Thank you,
Meghavvarnam Satish

Jul 23 '05
11 4479
Meghavvarnam wrote:
When we declare, we use auto_ptr. As you might already know, auto_ptr
is a mechanism that provides ownership to take care of releasing the
memory that we allocate with a new.

However, while calling new, specifically for an inbuilt type, we
specify the size of memory that we request with in square brackets.

And once the memory is allocated, we could use it like an array. We
could index into it too.
That would be wrong. 'auto_ptr' destroys the object using 'delete'.
If you allocate it using 'new[]', you _have_to_ use 'delete[]' and not
'delete'. So, 'auto_ptr' is not a suitable mechanism here.
[...]


V
Jul 23 '05 #11
Meghavvarnam wrote:
Apologies for the confusion in my previous post. Am pasting the above
piece of code that works again. Have reformatted it.

Please note the usage of the member function get () to get the address
of an auto_ptr variable.
[...]


Your code has undefined behaviour. If it happens to work on your
system, it's no indication that it's correct.

V
Jul 23 '05 #12

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

Similar topics

4
5153
by: Chucker | last post by:
Hi Folks, I got an error that drives me crazy because it only occurs sometimes and I can`t even reproduce it. I got a __gc class here is it`s header: #pragma once #include "../empLib/empImg.h"
6
5544
by: Anuradha | last post by:
Below is the code which was written VC++ 6.0 under windows environment. Executing the same throws: ------------------ Debug Error! Program: ccheck.exe DAMAGE: after normal block (#41) at 0x00300160 (Press Retry to debug the application) ------------------
5
859
by: Meghavvarnam | last post by:
Hi all, I just joined this group and am new to VC++. I wrote the code following the next para in C++ and used VC++ 6.0 Enterprise Edition to build and test. I had the following error message because of an exception that gets thrown when I call delete ipAddress; in the destructor - ~TrapDestination () :
1
2394
by: Adam Clauss | last post by:
I have a doc/view app w/ a CRichEditView. In it, I define: void CSyntaxView::ParseLine(long lineNum); This function starts off by getting the text of the specified line (into a CString): CRichEditCtrl* ctrl = &GetRichEditCtrl(); int lineLen = ctrl->LineLength(lineNum); char* buf = new char; ctrl->GetLine(lineNum, buf, lineLen);
18
2179
by: John Salerno | last post by:
I'm still tyring to figure out what "Pythonic" means, and I have a feeling the answer to my question may fall into that category. Are block comments somehow unpythonic?
8
3333
by: Alvin | last post by:
I'm making a very simple game in SDL, and I'm not asking for SDL help I hope - this looks like something C++ related, so I'll ask here. I have a class for a simple block, or tile, in the game, which can be either on or off. I'm having trouble with the constructor though. class block { private: SDL_Surface *screen;
3
1457
by: raan | last post by:
Whats wrong with the code ? delete tp; is throwing DAMAGE: After normal block(#56) at 0x00321480 Environment, VS2003, XP #include <iostream> #include <fstream> #include <string> #include <set> #include <stack> #include <sstream>
1
1551
by: Anjaneya | last post by:
Hi all, Here is the error message which i am getting: Damage: After normal block(#253) at 0x009E6A98 I am trying to calculate the dense disparity map for colour images. I am trying to do this in C using OpenCV. Here is the sample code where i am getting error message:
0
1234
by: Now You Know | last post by:
Water Damage Restoration 24 hour open 7 Days Phone 1 877 364 5264 When disaster strikes such as a washing machine overflow, bath overflow, burst pipe, rainwater from balcony etc, water damage restoration procedures must be followed. It is not as simple as just sucking up the water and cleaning the carpet and letting the area dry naturally. It is not the wet carpet that is the problem it is the underlay and the wood or concrete floor...
0
10852
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
10553
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
10596
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
10255
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9382
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4459
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4021
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.