Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Subject: Re: Re: BUG - Cygwin to GNU CC compatibility From: Robert Collins To: Arash Partow Cc: ejfried AT ca DOT sandia DOT gov, cygwin AT cygwin DOT com In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-X8dx9o6MOikHCKcll7fm" Date: 06 Aug 2002 11:32:08 +1000 Message-Id: <1028597528.8966.230.camel@lifelesswks> Mime-Version: 1.0 --=-X8dx9o6MOikHCKcll7fm Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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.=20 =20 > 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. =20 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. >=20 > 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. >=20 > 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. =20 > >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 =3D=3D class with all public members. new and new[] are completely appropriate. =20 > >3) I've only pointed out ONE of your memory management bugs. There are=20 > >plenty more in this code. >=20 > 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 --=-X8dx9o6MOikHCKcll7fm Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQA9TycXI5+kQ8LJcoIRAmtFAJ9A3sgLztT2/oJqZsvQMerNL59MUgCgxZvs XaFXJ1M0oh0Im3py9wiIbHo= =lXU2 -----END PGP SIGNATURE----- --=-X8dx9o6MOikHCKcll7fm--