473,496 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

is it a bug of "cppunitlite"?

Hi all:
Today, i read the source code of "cppunitlite", a obscure
problem come from the funciton: (the function reside in the
simplestring.cpp)

SimpleString SimpleString::operator= (const SimpleString&
other)
{
delete buffer; //???
buffer = new char [other.size() + 1];
strcpy(buffer, other.buffer);
return *this;
}

"buffer" is a instance of " char * ", so i want to know,the
statment "delete buffer", is it a ill statment? if not, why?
Sep 12 '08 #1
2 1419
In article
<24**********************************@i24g2000prf. googlegroups.com>,
"Le****@gmail.com" <Le****@gmail.comwrote:
Hi all:
Today, i read the source code of "cppunitlite", a obscure
problem come from the funciton: (the function reside in the
simplestring.cpp)

SimpleString SimpleString::operator= (const SimpleString&
other)
{
delete buffer; //???
buffer = new char [other.size() + 1];
strcpy(buffer, other.buffer);
return *this;
}

"buffer" is a instance of " char * ", so i want to know,the
statment "delete buffer", is it a ill statment? if not, why?
This is ill:

char* p = new char [1234];
delete p; // error, should be delete [] p
Sep 12 '08 #2
On Sep 12, 8:37 am, "Lew...@gmail.com" <Lew...@gmail.comwrote:
Today, i read the source code of "cppunitlite", a obscure
problem come from the funciton: (the function reside in the
simplestring.cpp)
SimpleString SimpleString::operator= (const SimpleString&
other)
{
delete buffer; //???
buffer = new char [other.size() + 1];
strcpy(buffer, other.buffer);
return *this;
}
"buffer" is a instance of " char * ", so i want to know,the
statment "delete buffer", is it a ill statment? if not, why?
It depends on how the memory for buffer was allocated, but a
priori, it's undefined behavior here, since the memory seems to
have been allocated by a new[].

As assignment operators go, this one is broken anyway. I don't
know where the code comes from, but the author obviously isn't
competent to write C++.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 12 '08 #3

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

Similar topics

10
2005
by: Luke Meyers | last post by:
So, just a little while ago I had this flash of insight. It occurred to me that, while of course in general there are very good reasons for the conventional two-file header/implementation...
0
6991
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...
0
7160
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,...
1
6878
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...
0
7373
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...
0
5456
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,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
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...
0
3088
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...
0
1405
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 ...

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.