Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 67805 invoked from network); 26 Apr 2006 01:05:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Apr 2006 01:05:18 -0000 Received: (qmail 93705 invoked by uid 500); 26 Apr 2006 01:05:18 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 93690 invoked by uid 500); 26 Apr 2006 01:05:17 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 93669 invoked by uid 99); 26 Apr 2006 01:05:17 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Apr 2006 18:05:17 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [208.30.140.160] (HELO moroha.quovadx.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Apr 2006 18:05:17 -0700 Received: from bco-exchange.bco.roguewave.com (bco-exchange.bco.roguewave.com [172.19.31.48]) by moroha.quovadx.com (8.13.4/8.13.4) with ESMTP id k3Q14Wkk031162 for ; Wed, 26 Apr 2006 01:04:33 GMT Received: from [10.70.3.113] (10.70.3.113 [10.70.3.113]) by bco-exchange.bco.roguewave.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id 2YG6D6DR; Tue, 25 Apr 2006 19:01:48 -0600 Message-ID: <444EC747.1090200@roguewave.com> Date: Tue, 25 Apr 2006 19:05:11 -0600 From: Martin Sebor User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050920 X-Accept-Language: en-us, en MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: Re: 21.string.replace length_error (win32, msvc-7.1) References: <4D6A8407B7AC6F4D95B0E55C4E7C4C6204171AA3@exmsk.moscow.vdiweb.com> In-Reply-To: <4D6A8407B7AC6F4D95B0E55C4E7C4C6204171AA3@exmsk.moscow.vdiweb.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Anton Pevtsov wrote: > The following code fails with access violation (segmentation fault on > Linux) error on Win32, MSVC-7.1 (Suse Linux, gcc 4.0.2) Strictly speaking, the behavior of this program is undefined since this overload of replace is specified to return s.replace (0, 1, string ("a", s.max_size() + 1)) and the expression string ("a", s.max_size() + 1) has undefined semantics due to the array "a" having fewer than the number of elements specified by the second argument. But from a QoI standpoint, since we don't actually invoke the ctor to create the temporary string from the array, we could detect and avoid the (potential) undefined behavior and throw the appropriate exception instead. Could you open a Jira issue and reference this thread in the archive in it? Thanks Martin > > #include > #include > #include > > static char long_string [4096] = {'a'}; > > int main (void) > { > try > { > std::string s (long_string, 4095); > s.replace (0, 1, "a", s.max_size () + 1); > > std::cout << "Expect length error, got nothing" << '\n'; > } > catch (std::length_error& e) > { > std::cout << "Got expected length error" << '\n'; > } > > return 0; > } > > > I suspect a bug in replace implementation, string.cc line 327: > The check > > __size0 - __xlen <= max_size () - __n2 > > is not enough in this case. > > > Could you take a look when you have a chance, please? > > > Thanks, > Anton Pevtsov