Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 48226 invoked from network); 25 Jun 2007 19:53:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Jun 2007 19:53:38 -0000 Received: (qmail 99861 invoked by uid 500); 25 Jun 2007 19:53:41 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 99841 invoked by uid 500); 25 Jun 2007 19:53:41 -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 99830 invoked by uid 99); 25 Jun 2007 19:53:41 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jun 2007 12:53:41 -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; Mon, 25 Jun 2007 12:53:35 -0700 Received: from qxvcexch01.ad.quovadx.com ([192.168.170.59]) by moroha.quovadx.com (8.13.6/8.13.6) with ESMTP id l5PJqklT017346 for ; Mon, 25 Jun 2007 19:52:47 GMT Received: from [10.70.3.113] ([10.70.3.113]) by qxvcexch01.ad.quovadx.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 25 Jun 2007 13:52:01 -0600 Message-ID: <46801DBC.90909@roguewave.com> Date: Mon, 25 Jun 2007 13:55:40 -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: Getting incorrect behavior on strstream References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 25 Jun 2007 19:52:01.0428 (UTC) FILETIME=[4C121540:01C7B762] X-Virus-Checked: Checked by ClamAV on apache.org I agree with Farid that test2() and test3() exhibit undefined behavior because they both fail to append the required NUL to the string before formatting it via the "%s" printf directive. But the test program does demonstrate a real problem, and that is the formatting of infinity when the stream precision is greater than 7. It looks as though the num_put facet inserts the string "inf\0\0ity" into the stream rather than "inf". A small test case is below. Please go ahead and open an issue for this in Jira. Martin $ cat u.cpp && make u && ./u | od -c #include #include #include int main () { std::ostringstream s; s.precision (8); s << 1 / 0.0; std::cout << s.str () << '\n'; assert (s.str () == "inf"); } gcc -c -I/build/sebor/stdcxx/include/ansi -D_RWSTDDEBUG -D_RWSTD_USE_CONFIG -I/build/sebor/stdcxx/include -I/build/sebor/stdcxx-gcc-4.1.0-11s/include -I/build/sebor/stdcxx/examples/include -pedantic -nostdinc++ -g -W -Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long u.cpp u.cpp: In function 'int main()': u.cpp:8: warning: division by zero in '1 / 0.' gcc u.o -o u -L/build/sebor/stdcxx-gcc-4.1.0-11s/lib -lstd11s -lsupc++ -lm Assertion failed: s.str () == "inf", file u.cpp, line 10 0000000 i n f \0 \0 i t y \n 0000011 Jeremy Dean wrote: > I have a testcase that is showing incorrect behavior ostrstream or > ostringstream: > > #include > #include > #include > #include > #include > #include > > void test1() { > std::ostringstream S; > long double x = std::pow(1e300,2); > S << "Something " << std::setprecision(8) << x; > S << " else"; > std::printf("Test1: %s\n", S.str().c_str()); > } > void test2() { > std::ostrstream S; > long double x = std::pow(1e300,2); > S << "Something " << std::setprecision(7) << x; > S << " else"; > std::printf("Test2: %s\n", S.str()); > } > void test3() { > std::ostrstream S; > long double x = 0.0/0.0; > S << "Something " << std::setprecision(8) << x; > S << " else"; > std::printf("Test3: %s\n", S.str()); > } > int main(int argc, char* argv[]) { > test1(); > test2(); > test3(); > } > > > On solaris 8 with Sun Studio 8 patch 14 I get the following output > > Test1: Something inf > Test2: Something inf else else > Test3: Something nan else > > Test1 is missing else > Test2 has an extra else > Test3 looks ok. > > On RedHat 3u6 I get the following output: > > Test1: Something inf else > Test2: Something inf else > Test3: Something nan elseing inf else > > Test1 and 2 look ok > Test3 however has extra output "ing inf else" > > Any thoughts on this problem? > > Thanks, > > Jeremy > > Jeremy Dean > Rogue Wave Software, > A QUOVADX(tm) division > Technical Support > Phone: 303-545-3205 -- 1-800-404-4767 > E-mail: support@roguewave.com > Web: http://www.roguewave.com/support > Knowledge Base entries: > http://www.roguewave.com/kbdocs/search.html > View issues online at: > http://www.roguewave.com/youraccount/login/ >