From: Peter Howkins Date: Wed, 21 Mar 2018 01:01:09 +0000 (+0000) Subject: Change how read and write errors are detected on fstream based streams. X-Git-Tag: 2.2.4a~188 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=abd209a83c82c1d3cdff5ee7fca3685256f66adf;p=oweals%2Fcde.git Change how read and write errors are detected on fstream based streams. --- diff --git a/cde/programs/dtinfo/DtMmdb/compression/zip.C b/cde/programs/dtinfo/DtMmdb/compression/zip.C index 1b8cb4f6..ad88c39e 100644 --- a/cde/programs/dtinfo/DtMmdb/compression/zip.C +++ b/cde/programs/dtinfo/DtMmdb/compression/zip.C @@ -67,7 +67,8 @@ void zip::compress(const buffer& uncompressed, buffer& compressed) if ( !out ) throw(streamException(out.rdstate())); - if ( out.write(uncompressed.get_base(), uncompressed.content_sz()) == 0 ) + out.write(uncompressed.get_base(), uncompressed.content_sz()); + if ( out.bad() ) throw(streamException(out.rdstate())); out.close(); @@ -84,7 +85,8 @@ void zip::compress(const buffer& uncompressed, buffer& compressed) compressed.expand_chunk(x); - if ( in.read(compressed.get_base(), x) == 0 || x != in.gcount() ) + in.read(compressed.get_base(), x); + if ( in.bad() || x != in.gcount() ) throw(streamException(in.rdstate())); compressed.set_content_sz(x); @@ -102,7 +104,8 @@ void zip::decompress(buffer& compressed, buffer& uncompressed) if ( !out ) throw(streamException(out.rdstate())); - if ( out.write(compressed.get_base(), compressed.content_sz()) == 0 ) + out.write(compressed.get_base(), compressed.content_sz()); + if ( out.bad() ) throw(streamException(out.rdstate())); out.close(); @@ -119,7 +122,8 @@ void zip::decompress(buffer& compressed, buffer& uncompressed) uncompressed.expand_chunk(x); - if ( in.read(uncompressed.get_base(), x) == 0 || x != in.gcount() ) + in.read(uncompressed.get_base(), x); + if ( in.bad() || x != in.gcount() ) throw(streamException(in.rdstate())); uncompressed.set_content_sz(x); diff --git a/cde/programs/dtinfo/DtMmdb/storage/unixf_storage.C b/cde/programs/dtinfo/DtMmdb/storage/unixf_storage.C index c87dae60..fd55d170 100644 --- a/cde/programs/dtinfo/DtMmdb/storage/unixf_storage.C +++ b/cde/programs/dtinfo/DtMmdb/storage/unixf_storage.C @@ -208,12 +208,14 @@ unixf_storage::readString(mmdb_pos_t loc, char* base, int len, int str_off) int offset = int(loc) + str_off; - if ( seekg( offset, ios::beg ) == 0 ) { + seekg( offset, ios::beg ); + if ( bad() ) { MESSAGE(cerr, "seekg failed"); throw(streamException(fstream::rdstate())); } - if ( read( base, len ) == 0 || len != fstream::gcount() ) { + read( base, len ); + if ( bad() || len != fstream::gcount() ) { MESSAGE(cerr, "read() failed"); throw(streamException(fstream::rdstate())); }