http://llvm.org/bugs/show_bug.cgi?id=14074

             Bug #: 14074
           Summary: std::filebuf:sputn fails to write 0xFF as the first
                    byte into the filebuf, irregardless of the openmode
           Product: libc++
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]
    Classification: Unclassified


std::filebuf::sputn fails to write 0xFF as the first byte into the buffer. It
however reports the byte as written via the return code.  

The openmode does not affect the behavior.

This breaks libraries which use the filebuf directly (i.e.
boost::iostreams::device::file_sink).

This works correctly using libstdc++ as well as the standard library shipped
with Visual C++.


Steps:
  1) Instantiate a filebuf
  2) Call sputn with a buffer starting with 0xFF

Observed behavior:
  sputn() returns the byte as having been written but no byte is put into the
buffer.

Expected behavior:
  The byte should be written into the buffer.


$ cat badfilebuf.cpp 
#include <fstream>
#include <iostream>

int main() {
    std::filebuf buf;
    buf.open("buf", std::ios::out | std::ios::binary);
    std::cout << buf.sputn("\xFF", 1) << " bytes written" << std::endl;
    buf.close();

    return 0;
}

$ clang++ badfilebuf.cpp 
$ ./a.out
1 bytes written
$ ls -l buf
-rw-r--r--  1 andrew  staff  1 Oct 12 15:08 buf
$ clang++ badfilebuf.cpp -stdlib=libc++
$ ./a.out
1 bytes written
$ ls -l buf
-rw-r--r--  1 andrew  staff  0 Oct 12 15:08 buf

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to