[cfe-dev] [libcxx]: a testsuite bug involving trailing null in strstream

soaliap soaliap at 126.com
Mon Sep 17 23:09:02 PDT 2012


I compiled libcxx and libcxxabi (tags/release_30/final) by Fujitsu's c++
compiler on linux.
But when I running ./testit in libcxx/test directory, there were some
assertion fails, like:
----------------------------------------------------------------------
a.out: cp_size_mode.pass.cpp:39: int main(): Assertion `out.str() ==
std::string("123 4.5 dog321 5.5 cat")' failed.
Aborted (core dumped)
----------------------------------------------------------------------

Then I found here
    http://llvm.org/viewvc/llvm-project?view=rev&revision=157832
hhinnant fixed a few testsuite bugs involving trailing null (or lack
thereof) in strstream.

But there still were a few problems, taking 
   
test/depr/depr.str.strstreams/depr.ostrstream/depr.ostrstream.cons/cp_size_mode.pass.cpp 
for example:
----------------------------------------------------------------------
#include <strstream>
#include <cassert>

int main()
{
    {
        char buf[] = "123 4.5 dog";
        std::ostrstream out(buf, 0);                    // #1, the buffer
size of obeject out is strlen(buf)
        assert(out.str() == std::string("123 4.5 dog"));
        int i = 321;
        double d = 5.5;
        std::string s("cat");
        out << i << ' ' << d << ' ' << s << std::ends;    // #2, strlen("321
5.5 cat") == strlen(buf), so std::ends cannot append to the tail of out
        assert(out.str() == std::string("321 5.5 cat"));
    }
    {
        char buf[23] = "123 4.5 dog";
        std::ostrstream out(buf, 11, std::ios::app);    // #3, the addible
buffer size of obeject out is 11
        assert(out.str() == std::string("123 4.5 dog"));
        int i = 321;
        double d = 5.5;
        std::string s("cat");
        out << i << ' ' << d << ' ' << s << std::ends;  // #4, strlen("321
5.5 cat") == 11, so std::ends cannot append to the tail of out
        assert(out.str() == std::string("123 4.5 dog321 5.5 cat"));
    }
}
----------------------------------------------------------------------

I find there are two testsuites which have the same problem:
----------------------------------------------------------------------
(1)
test/depr/depr.str.strstreams/depr.ostrstream/depr.ostrstream.cons/cp_size_mode.pass.cpp
(2)
test/depr/depr.str.strstreams/depr.strstream/depr.strstream.cons/cp_size_mode.pass.cpp
----------------------------------------------------------------------


-Zhang Xiongpang



--
View this message in context: http://clang-developers.42468.n3.nabble.com/libcxx-a-testsuite-bug-involving-trailing-null-in-strstream-tp4026743.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list