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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

ZhangXiongpang
This post was updated on .
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 a null character cannot be appended to the tail of out,
                                                                       //   fortunatly, there is already a null character at the tail of buf, so the next assert will not fail
        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 a null character cannot be appended to the tail of out, so the next assert will fail
        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