Opened 13 years ago

Last modified 8 years ago

#3935 new Bugs

stream<file_sink> does not throw an exception and not set fail/bad bits when file is wrong

Reported by: zxspeccy.cpp@… Owned by: Jonathan Turkanis
Milestone: Boost 1.43.0 Component: iostreams
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

I'm trying to write some content to a new file using boost::stream<file_sink> class. Unfortunately errors/failures during opening the file are ignored by boost library.

See attached test.cpp file for snippet.

Above program is started as non root user and have not access for file /wrong.txt

Result is:
mariusz@ppbw:~/boost-1.42$ ./test
boost ver:1_42
0 0
nothing thrown

mariusz@ppbw:~/boost-1.42$ ls /
bin dev initrd.img lost+found opt sbin tmp vmlinuz
boot etc initrd.img.old media proc srv usr vmlinuz.old
cdrom home lib mnt root sys var

mariusz@ppbw:~/boost-1.42$ ldd ./test

linux-gate.so.1 => (0xb7fc4000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7eb0000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7e8a000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7e6c000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d0e000)
/lib/ld-linux.so.2 (0xb7faa000)

mariusz@ppbw:~/boost-1.42$

Similar program using std::ofstream works as I expected:

  • console prints: 1 0
  • exception is thrown

I made tests using:
boost 1.42
Ubuntu 8.10 intrepid
g++ (Debian 4.3.2-1.1) 4.3.2

Attachments (1)

test.cpp (617 bytes ) - added by zxspeccy.cpp@… 13 years ago.
Program, which should throw an exception, but instead it just ignore failures

Download all attachments as: .zip

Change History (2)

by zxspeccy.cpp@…, 13 years ago

Attachment: test.cpp added

Program, which should throw an exception, but instead it just ignore failures

comment:1 by anonymous, 8 years ago

Five years and this serious bug is still open?

As a workaround, use file_descriptor_sink. That one throws an exception if the file can't be opened.

Note: See TracTickets for help on using tickets.