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 From: swamp-dog AT ntlworld DOT com (Guy Harrison) To: Subject: Re: BUG - Cygwin to GNU CC compatibility Date: Mon, 05 Aug 2002 18:28:33 GMT Message-ID: <3d53c3ad.348473929@smtp.ntlworld.com> References: <200208051455 DOT HAA28027 AT ca DOT sandia DOT gov> In-Reply-To: <200208051455.HAA28027@ca.sandia.gov> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id g75ITtX19137 On Mon, 5 Aug 2002 07:55:56 -0700 (PDT), ejfried AT ca DOT sandia DOT gov (friedman_hill ernest j) wrote: >Arash, > >If your program runs on a bunch of systems, well, you're just lucky, >because the bugs are in your code, not in cygwin. You've provided a >constructor (whitespace edited to make this email shorter) > >DigitList::DigitList(DigitList const &diglst) { > *this = diglst; >}; > >which just invokes, implicitly, the default copy constructor. Default assignment operator? ;-) >This >default copy constructor would look something like this: > >DigitList::DigitList(DigitList &diglst) { > this.digitList = diglist.digitList; // *** This line > this.listSize = diglist.listSize; >} > >The line I've marked with a *** is the trouble maker -- it makes an >alias for the pointer member digitList (which is effectively an >int*). When you copy a DigitList using this copy ctor, you get two >DigitLists sharing a single digitList pointer. > >Now, in your dtor: > >DigitList::~DigitList() { > listSize = 0; > free(digitList); >}; > >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. The implementation is allowed to do anything now: it can >keep running without a problem, it can crash (as cygwin's newlib is >apparently doing) or it can send dirty pictures of itself to the >White House. > >Anyway, so you should THANK cygwin for finding the bugs in your >code. BTW, 1) why are you using free and malloc instead of new and >delete, anyway? and 2) Why are you writing a class like DigitList in the >first place -- why not simply use a vector? and 3) I've only >pointed out ONE of your memory management bugs. There are plenty more >in this code. [snip] -- swamp-dog AT ntlworld DOT com -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/