Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
From: swamp-dog@ntlworld.com (Guy Harrison)
To: <cygwin@cygwin.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.HAA28027@ca.sandia.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@ca.sandia.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@ntlworld.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/

