Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 37130 invoked from network); 27 Apr 2006 16:08:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Apr 2006 16:08:22 -0000 Received: (qmail 42579 invoked by uid 500); 27 Apr 2006 16:08:20 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 42566 invoked by uid 500); 27 Apr 2006 16:08:20 -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 42551 invoked by uid 99); 27 Apr 2006 16:08:20 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Apr 2006 09:08:20 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of AntonP@moscow.vdiweb.com designates 195.210.189.132 as permitted sender) Received: from [195.210.189.132] (HELO mail.moscow.vdiweb.com) (195.210.189.132) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Apr 2006 09:08:19 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Subject: RE: 21.string.replace length_error (win32, msvc-7.1) Date: Thu, 27 Apr 2006 20:07:56 +0400 Message-ID: <4D6A8407B7AC6F4D95B0E55C4E7C4C62041F4A9F@exmsk.moscow.vdiweb.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: 21.string.replace length_error (win32, msvc-7.1) Thread-Index: AcZozYl5flXQL86JTSeGavlF/BbaLwBRxsFg From: "Anton Pevtsov" To: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N The Jira issue created: http://issues.apache.org/jira/browse/STDCXX-175 Thanks, Anton Pevtsov -----Original Message----- From: Martin Sebor [mailto:sebor@roguewave.com]=20 Sent: Wednesday, April 26, 2006 05:05 To: stdcxx-dev@incubator.apache.org Subject: Re: 21.string.replace length_error (win32, msvc-7.1) 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 >=20 > #include > #include > #include >=20 > static char long_string [4096] =3D {'a'}; >=20 > int main (void) > { > try=20 > { > std::string s (long_string, 4095); > s.replace (0, 1, "a", s.max_size () + 1); >=20 > std::cout << "Expect length error, got nothing" << '\n'; > } > catch (std::length_error& e) > { > std::cout << "Got expected length error" << '\n'; > } >=20 > return 0; > } >=20 >=20 > I suspect a bug in replace implementation, string.cc line 327: The=20 > check >=20 > __size0 - __xlen <=3D max_size () - __n2 >=20 > is not enough in this case. >=20 >=20 > Could you take a look when you have a chance, please? >=20 >=20 > Thanks, > Anton Pevtsov