[llvm-bugs] [Bug 42572] New: std::ofstream silently fails to write files when they can't be created

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 10 19:22:09 PDT 2019


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

            Bug ID: 42572
           Summary: std::ofstream silently fails to write files when they
                    can't be created
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: yuri at tsoft.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

The example from cplusplus.com
http://www.cplusplus.com/reference/fstream/ofstream/open/ with the modified
file name fails silently, showing how error-prone the file interface is:


> #include <fstream>
> 
> int main () {
>   std::ofstream ofs;
>   ofs.open ("nonexistent-noexistent/test.txt", std::ofstream::out | std::ofstream::app);
> 
>   ofs << " more lorem ipsum";
> 
>   ofs.close();
> 
>   return 0;
> }

No exception is thrown, no error message is printed.

The kernel trace shows that the error "No such file or directory" is lost by
STL:
> 47377 ofstream CALL  open(0x20229d,0x209<O_WRONLY|O_APPEND|O_CREAT>,0666<S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH>)
> 47377 ofstream NAMI  "nonexistent-noexistent/test.txt"
> 47377 ofstream RET   open -1 errno 2 No such file or directory


FreeBSD 12 amd64, clang8.


Yuri

-- 
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/20190711/ecc7d028/attachment-0001.html>


More information about the llvm-bugs mailing list