Boost Users :
From: Paul Giaccone (paulg_at_[hidden])
Date: 2006-01-19 12:02:58
How can you deal with a corrupt file when using filters?
I have a chain of filters that includes a bzip2 and multichar filter
have written myself. If the read() function fails to find what it
expects in the file, it returns 0 (meaning "no characters read").
Otherwise it returns the number of characters read (which should be
equal to the number of characters requested in the third function
parameter) or -1 if the end of the file is reached.
This works fine if the file is as is required, but if it is corrupted in
any way, the program either hangs or crashes at
if (s->strm != strm) return BZ_PARAM_ERROR;
in bzlib.c, with s as a pointer that cannot be read (set to 0xcdcdcdcd).
I'm working in Microsoft Visual C++ and gcc 3.2.3.
How should this be handled? I haven't seen anything about it in the
documentation. I imagine I should throw an exception instead of
returning 0 (perhaps an iostreams exception?). Given that the crash is
the bzip2 (bzip2 being the first operation done when deserialising the
file), where would I put the associated catch block?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net