delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/08/05/14:29:56

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
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: <cygwin AT cygwin DOT com>
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
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<int>? 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019