This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: BUG - Cygwin to GNU CC compatibility


On Tue, 2002-08-06 at 10:58, Arash Partow wrote:
> this is a perfectly valid copy constructor.

No one claimed it was invalid. It's just not correct. 
 
> when you do the copy constructor the whole object and its variable
> contents is copied automaically no need for any of the stuff you
> just wrote.
 
Thats the point: a shallow copy of the object is incorrect because you
are using remote storage.

> The program does not any any way use any variable more than once,
> not in the test that i have given you nor in the actuall class code.
> So what you are saying is not possible, and hence if you think it
> is occuring instead of writing about it, just give a simple answer
> like on line so and so this is happening. if you give an example of
> it then i will accept your argument :D

Line 18, countertest.cpp invokes the DigitList copy constructor and then
the DigitList destructor.

> >you free digitList. But if two objects sharing a digitList both delete
> >the same pointer, then you've crossed over into the realm of undefined
> >behaviour.
> 
> no two objects are using digitList, hence no crossing over into the
> twilight-zone.

You construct a digitList and then pass it to the CounterBlock
constructor, which invokes a copy on the digitList, and as you have no
deep copy routine, the original array is freed. Thus two objects are
using the digitList.

> >Anyway, so you should THANK cygwin for finding the bugs in your
> >code.
> 
> I  found a bug in cygwin not the other way round. it can't handle
> not initialised object parameter passing or something else.

It can't handle you accessing memory that has been freed - which is
absoltely correct. Run your code under borland with boundschecker, or
under valgrind on linux and it will fail as well. The fact that other
platforms are more lenient with deferencing freed memory is *NOT* a bug
in cygwin.
 
> >BTW, 1) why are you using free and malloc instead of new and
> >delete, anyway?
> if you actually looked at the code, malloc was used for the
> initialisation of a structure not a class, i don't know where you
> come from but on earth we use malloc to initialise and structure
> on memory according to its size.

In C++ a struct == class with all public members. new and new[] are
completely appropriate.
 
> >3) I've only pointed out ONE of your memory management bugs. There are 
> >plenty more in this code.
> 
> feel free to point out more if you can find any, i will continue issue
> this as a bug to cygwin.
> until either a patch comes along or someone can explain why it works
> on every other os and compiler except for when its compiled by cygwin.

You'll be waiting a long time then. Your code is incorrect. It violates
basic principles of remote ownership and is a classic deep copy problem.

You've been given excellent, accurate advice. Take it or leave it.

Rob

Attachment: signature.asc
Description: This is a digitally signed message part


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]