From stdcxx-dev-return-3515-apmail-incubator-stdcxx-dev-archive=incubator.apache.org@incubator.apache.org Sat May 26 00:04:01 2007 Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 29583 invoked from network); 26 May 2007 00:04:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 May 2007 00:04:01 -0000 Received: (qmail 74395 invoked by uid 500); 26 May 2007 00:04:06 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 74381 invoked by uid 500); 26 May 2007 00:04:06 -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 74370 invoked by uid 99); 26 May 2007 00:04:06 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 May 2007 17:04:06 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.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; Fri, 25 May 2007 17:03:58 -0700 Received: from qxvcexch01.ad.quovadx.com ([192.168.170.59]) by moroha.quovadx.com (8.13.6/8.13.6) with ESMTP id l4Q03aUn031030 for ; Sat, 26 May 2007 00:03:36 GMT Received: from [10.70.3.113] ([10.70.3.113]) by qxvcexch01.ad.quovadx.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 25 May 2007 18:03:01 -0600 Message-ID: <465779AD.4020201@roguewave.com> Date: Fri, 25 May 2007 18:05:01 -0600 From: Martin Sebor Organization: Rogue Wave Software User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070221 SeaMonkey/1.1.1 MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: Re: [PATCH] RE: [jira] Created: (STDCXX-427) SIGSEGV in istringstream::str() References: <26166494.1179958456146.JavaMail.jira@brutus> <7BDB2168BEAEF14C98F1901FD2DE6438868EBF@epmsa009.minsk.epam.com> <46563921.8030505@roguewave.com> <7BDB2168BEAEF14C98F1901FD2DE6438869047@epmsa009.minsk.epam.com> In-Reply-To: <7BDB2168BEAEF14C98F1901FD2DE6438869047@epmsa009.minsk.epam.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 26 May 2007 00:03:02.0018 (UTC) FILETIME=[3A137E20:01C79F29] X-Virus-Checked: Checked by ClamAV on apache.org Farid Zaripov wrote: [...] > The basic_stringbuf<>::str (const char_type *, _RWSTD_SIZE_T) > have the assertions at begin and at end (sstream.cc line 72 and 167), > and > both assertions passes. Ah, yes, thanks for the pointer! I was looking at the other two overloads in the header that just call the one in the .cc file and didn't realize that that one was the workhorse. > > The bug is in that len calculated as highmark - pbase(), but pbase() > == 0 > when buffer opened only in input mode. The begin of the buffer is always > this->_C_buffer with any openmode. So len = highmark - _C_buffer is > correct, I think. In input mode (only) the function is supposed to return: string(eback(), egptr()); In output mode (or input | output) the function must return: string(pbase(), high_mark); So unless I'm missing something the program below should be a valid (albeit incomplete) test case. Let me know what you think. #include #include #include int main () { struct Buf: std::stringbuf { Buf (std::string s, std::ios::openmode m) : std::stringbuf (s, m) { } void setget (int beg, int cur, int end) { setg (eback () + beg, eback () + cur, eback () + end); } void setput (int beg, int cur, int end) { setp (pbase () + beg, pbase () + end); pbump (cur); } }; { Buf buf ("abcde", std::ios::in); buf.setget (1, 2, 4); std::printf ("%s\n", buf.str ().c_str ()); assert ("bcd" == buf.str ()); } { Buf buf ("abcde", std::ios::out); buf.setput (1, 2, 4); std::printf ("%s\n", buf.str ().c_str ()); assert ("bcd" == buf.str ()); } } Martin