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

            Bug ID: 48912
           Summary: stream sentry leaks exceptions
           Product: libc++
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: l...@ncbi.nlm.nih.gov
                CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com

Created attachment 24429
  --> https://bugs.llvm.org/attachment.cgi?id=24429&action=edit
test case

Since basic_[io]stream::sentry gets constructed outside the try/catch blocks in
most (if not all) I/O methods, and, in case of istream::sentry, does not have a
try/catch block on its own (in the ctor), it lets the lower-level exceptions
leak to the user code.

Consider an istream doing a string input, with "is >> str".

If white space is skipped (as it usually is the case), then there's some I/O
occurring within the sentry ctor.  If that I/O (stream buffer operation) causes
the streambuf to throw, the exception is not caught, as it should at the
"operator>>" level, but gets leaked out.  Also, "badbit" is not set (as the
standard mandates), and the stream data integrity is, thus, compromised.

This bug is both in versions 10 and 11 of libc++.

Attached is the simple code that demonstrates the issue.

When built with clang++, it produces:

> clang++ test.cpp
> ./a.out
caught
0

which basically shows there was an exception and the stream is in "good" state.

When built with a standard-conforming implementation, the output is this:

> ./a.out
5

Note: 5 = 1(badbit) + 4(failbit).  That is the correct behavior of this
extraction operation.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to