[llvm-bugs] [Bug 24437] New: basic_ostream::write() does not call basic_streambuf::sputn() if n is zero

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 12 08:55:22 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24437

            Bug ID: 24437
           Summary: basic_ostream::write() does not call
                    basic_streambuf::sputn() if n is zero
           Product: libc++
           Version: 3.4
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sadyrovr at ncbi.nlm.nih.gov
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
    Classification: Unclassified

Hello,

We have a cross-platform library that is compiled by GCC, ICC, MS VS and Clang
compilers on a few platforms.
There is a template code in the library which uses basic_iostream with a class
derived from basic_streambuf.
That class (based on basic_streambuf) creates a file on first write (there
might be none writes and only reads).
In some instantiations of that template code basic_iostream::write() is called
only once, with n = 0.

In this case, Clang/libc++ compiled code does not call basic_streambuf::sputn()
(which in turn calls xsputn() of our class).
Consequently, that file we expect to exist is not created.

We have no such issue with this code compiled by any other compiler we use.
(Our implementation of xsputn() is called in this case and files are created).

We took a look at the source code of libc++
(http://llvm.org/svn/llvm-project/libcxx/trunk/include/ostream) for this
particular issue and found the cause:

basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
...
        if (__sen && __n)
        {
            if (this->rdbuf()->sputn(__s, __n) != __n)
...

We checked the source code of libstdc++ as well, it does not check for n being
non-zero.
It seems all other implementations of standard library we use do not do this as
well (otherwise, we would have experienced the same issue).

Could someone take a look at this?

Thanks,
Rafael.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150812/0c73fe1e/attachment.html>


More information about the llvm-bugs mailing list