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 Message-ID: <3FC76805.1050601@inf.ethz.ch> Date: Fri, 28 Nov 2003 16:21:41 +0100 From: Fabrice Marchal User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Code generation bug for operator new[] when -fcheck-new in GCC 3.3.1 References: <000001c3b5c2$bad46370$6400a8c0 AT DELL2K> In-Reply-To: <000001c3b5c2$bad46370$6400a8c0@DELL2K> X-Enigmail-Version: 0.76.4.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at inf.ethz.ch X-Spam-Checker-Version: SpamAssassin 2.60 (1.212-2003-09-23-exp) on medoc This looks similar to the problem I have with gcc 3.31 and mysql: my code crashes after a constructor() as well. But it works on Linux (with gcc 3.3.1), so is it a cygwin or gcc-on-cygwin problem? Tom Scott wrote: >This bug is more properly a bug with GCC and not with cygwin - it shows up >in GCC 3.2.2 (i386-redhat-linux) as well. So I've submitted the problem to >GCC Bugzilla. It's Bug 13215. - Tom > >-----Original Message----- >From: Tom Scott [mailto:tscott AT StorageMatrix DOT com] >Sent: Wednesday, November 26, 2003 4:17 PM >To: cygwin AT cygwin DOT com >Subject: Code generation bug for operator new[] when -fcheck-new in GCC >3.3.1 > > >I've found that the following sample, which uses nothrow memory allocation >semantics, generates a segmentation violation: > >// g++ -g -fcheck-new -fno-exceptions -fno-rtti sample.cpp #include > > >class foo { >public: > int v; > foo(){ v = 0; } > ~foo() {} > void* operator new[](size_t size) { > return 0; // simulated memory failure > } > void operator delete[](void* p, size_t size) { } >}; > >main() >{ > foo *p = new foo[2]; > // p==4 here > if (p) delete [] p; > return 0; >} > >The segmentation violation results from a bug in the code that is generated >to call operator new[]. The return of operator new[] is correctly checked >for non-zero before calling the ctor ("-fcheck-new" semantics), but this >return value is subsequently incremented by 4. As a result, p is set to 4 >(not 0) when memory runs out. > >A work around is to modify applications so that the return value of "new >class[]" is checked and to treat a return of 4 the same as 0. > >Tom > > >-- >Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple >Problem reports: http://cygwin.com/problems.html >Documentation: http://cygwin.com/docs.html >FAQ: http://cygwin.com/faq/ > > > > > -- ======================================================================== Fabrice Marchal http://www.inf.ethz.ch/~marchal fabrice DOT marchal AT ieee DOT org marchal AT inf DOT ethz DOT ch +41-(0)1-632-56-79 ETH Zurich, CoLab Computational Laboratory FAX:+41-(0)1-632-17-03 ======================================================================== -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/