diff --git a/src/lib/util/chd.cpp b/src/lib/util/chd.cpp index f5e5ec8e0cc..90a8aece75d 100644 --- a/src/lib/util/chd.cpp +++ b/src/lib/util/chd.cpp @@ -135,7 +135,7 @@ struct chd_file::metadata_hash // stream in bigendian order //------------------------------------------------- -inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base)const +inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base) const noexcept { util::sha1_t result; memcpy(&result.m_raw[0], base, sizeof(result.m_raw)); @@ -148,7 +148,7 @@ inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base)const // stream in bigendian order //------------------------------------------------- -inline void chd_file::be_write_sha1(uint8_t *base, util::sha1_t value) +inline void chd_file::be_write_sha1(uint8_t *base, util::sha1_t value) noexcept { memcpy(base, &value.m_raw[0], sizeof(value.m_raw)); } @@ -339,7 +339,7 @@ bool chd_file::parent_missing() const noexcept * @return A sha1_t. */ -util::sha1_t chd_file::sha1() +util::sha1_t chd_file::sha1() const noexcept { try { @@ -350,7 +350,7 @@ util::sha1_t chd_file::sha1() } catch (std::error_condition const &) { - // on failure, return nullptr + // on failure, return null return util::sha1_t::null; } } @@ -368,7 +368,7 @@ util::sha1_t chd_file::sha1() * @return A sha1_t. */ -util::sha1_t chd_file::raw_sha1() +util::sha1_t chd_file::raw_sha1() const noexcept { try { @@ -383,7 +383,7 @@ util::sha1_t chd_file::raw_sha1() } catch (std::error_condition const &) { - // on failure, return nullptr + // on failure, return null return util::sha1_t::null; } } @@ -401,7 +401,7 @@ util::sha1_t chd_file::raw_sha1() * @return A sha1_t. */ -util::sha1_t chd_file::parent_sha1() +util::sha1_t chd_file::parent_sha1() const noexcept { try { @@ -542,20 +542,34 @@ std::error_condition chd_file::hunk_info(uint32_t hunknum, chd_codec_type &compr * @param rawdata The rawdata. */ -void chd_file::set_raw_sha1(util::sha1_t rawdata) +std::error_condition chd_file::set_raw_sha1(util::sha1_t rawdata) noexcept { + uint64_t const offset = (m_rawsha1_offset != 0) ? m_rawsha1_offset : m_sha1_offset; + assert(offset != 0); + // create a big-endian version uint8_t rawbuf[sizeof(util::sha1_t)]; be_write_sha1(rawbuf, rawdata); - // write to the header - uint64_t offset = (m_rawsha1_offset != 0) ? m_rawsha1_offset : m_sha1_offset; - assert(offset != 0); - file_write(offset, rawbuf, sizeof(rawbuf)); + try + { + // write to the header + file_write(offset, rawbuf, sizeof(rawbuf)); - // if we have a separate rawsha1_offset, update the full sha1 as well - if (m_rawsha1_offset != 0) - metadata_update_hash(); + // if we have a separate rawsha1_offset, update the full sha1 as well + if (m_rawsha1_offset != 0) + metadata_update_hash(); + } + catch (std::error_condition const &err) + { + return err; + } + catch (std::bad_alloc const &) + { + return std::errc::not_enough_memory; + } + + return std::error_condition(); } /** @@ -570,19 +584,23 @@ void chd_file::set_raw_sha1(util::sha1_t rawdata) * @param parent The parent. */ -void chd_file::set_parent_sha1(util::sha1_t parent) +std::error_condition chd_file::set_parent_sha1(util::sha1_t parent) noexcept { // if no file, fail if (!m_file) - throw std::error_condition(error::INVALID_FILE); + return std::error_condition(error::INVALID_FILE); + + assert(m_parentsha1_offset != 0); // create a big-endian version uint8_t rawbuf[sizeof(util::sha1_t)]; be_write_sha1(rawbuf, parent); // write to the header - assert(m_parentsha1_offset != 0); - file_write(m_parentsha1_offset, rawbuf, sizeof(rawbuf)); + try { file_write(m_parentsha1_offset, rawbuf, sizeof(rawbuf)); } + catch (std::error_condition const &err) { return err; } + + return std::error_condition(); } /** @@ -969,9 +987,9 @@ std::error_condition chd_file::read_hunk(uint32_t hunknum, void *buffer) if (blockoffs != 0) file_read(blockoffs, dest, m_hunkbytes); else if (m_parent_missing) - throw std::error_condition(error::REQUIRES_PARENT); + return std::error_condition(error::REQUIRES_PARENT); else if (m_parent) - m_parent->read_hunk(hunknum, dest); + return m_parent->read_hunk(hunknum, dest); else memset(dest, 0, m_hunkbytes); return std::error_condition(); @@ -2608,7 +2626,7 @@ void chd_file::hunk_copy_from_self(uint32_t hunknum, uint32_t otherhunk) // only permitted to reference prior hunks if (otherhunk >= hunknum) - throw std::error_condition(std::errc::invalid_argument); + throw std::error_condition(error::HUNK_OUT_OF_RANGE); // update the map entry uint8_t *rawmap = &m_rawmap[hunknum * 12]; @@ -3009,7 +3027,9 @@ std::error_condition chd_file_compressor::compress_continue(double &progress, do osd_work_queue_wait(m_read_queue, 30 * osd_ticks_per_second()); if (!compressed()) return std::error_condition(); - set_raw_sha1(m_compsha1.finish()); + std::error_condition err = set_raw_sha1(m_compsha1.finish()); + if (err) + return err; return compress_v5_map(); } } @@ -3166,23 +3186,26 @@ void chd_file_compressor::async_read() { // do the read uint8_t *dest = &m_work_buffer[0] + (m_read_done_offset % work_buffer_bytes); - assert(dest == &m_work_buffer[0] || dest == &m_work_buffer[work_buffer_bytes/2]); + assert(dest == &m_work_buffer[0] || dest == &m_work_buffer[work_buffer_bytes / 2]); uint64_t end_offset = m_read_done_offset + numbytes; - // if walking the parent, read in hunks from the parent CHD if (m_walking_parent) { + // if walking the parent, read in hunks from the parent CHD uint8_t *curdest = dest; for (uint64_t curoffs = m_read_done_offset; curoffs < end_offset + 1; curoffs += hunk_bytes()) { - m_parent->read_hunk(curoffs / hunk_bytes(), curdest); + std::error_condition err = m_parent->read_hunk(curoffs / hunk_bytes(), curdest); + if (err) + throw err; curdest += hunk_bytes(); } } - - // otherwise, call the virtual function else + { + // otherwise, call the virtual function read_data(dest, m_read_done_offset, numbytes); + } // spawn off work for each hunk for (uint64_t curoffs = m_read_done_offset; curoffs < end_offset; curoffs += hunk_bytes()) diff --git a/src/lib/util/chd.h b/src/lib/util/chd.h index d5a813944e0..7c293f7424e 100644 --- a/src/lib/util/chd.h +++ b/src/lib/util/chd.h @@ -309,18 +309,18 @@ public: uint32_t hunk_count() const noexcept { return m_hunkcount; } uint32_t unit_bytes() const noexcept { return m_unitbytes; } uint64_t unit_count() const noexcept { return m_unitcount; } - bool compressed() const { return (m_compression[0] != CHD_CODEC_NONE); } + bool compressed() const noexcept { return (m_compression[0] != CHD_CODEC_NONE); } chd_codec_type compression(int index) const noexcept { return m_compression[index]; } chd_file *parent() const noexcept { return m_parent.get(); } bool parent_missing() const noexcept; - util::sha1_t sha1(); - util::sha1_t raw_sha1(); - util::sha1_t parent_sha1(); + util::sha1_t sha1() const noexcept; + util::sha1_t raw_sha1() const noexcept; + util::sha1_t parent_sha1() const noexcept; std::error_condition hunk_info(uint32_t hunknum, chd_codec_type &compressor, uint32_t &compbytes); // setters - void set_raw_sha1(util::sha1_t rawdata); - void set_parent_sha1(util::sha1_t parent); + std::error_condition set_raw_sha1(util::sha1_t rawdata) noexcept; + std::error_condition set_parent_sha1(util::sha1_t parent) noexcept; // file create std::error_condition create(std::string_view filename, uint64_t logicalbytes, uint32_t hunkbytes, uint32_t unitbytes, const chd_codec_type (&compression)[4]); @@ -372,8 +372,8 @@ private: struct metadata_hash; // inline helpers - util::sha1_t be_read_sha1(const uint8_t *base) const; - void be_write_sha1(uint8_t *base, util::sha1_t value); + util::sha1_t be_read_sha1(const uint8_t *base) const noexcept; + void be_write_sha1(uint8_t *base, util::sha1_t value) noexcept; void file_read(uint64_t offset, void *dest, uint32_t length) const; void file_write(uint64_t offset, const void *source, uint32_t length); uint64_t file_append(const void *source, uint32_t length, uint32_t alignment = 0); diff --git a/src/lib/util/chdcodec.cpp b/src/lib/util/chdcodec.cpp index c59d880374c..c0110002265 100644 --- a/src/lib/util/chdcodec.cpp +++ b/src/lib/util/chdcodec.cpp @@ -553,7 +553,7 @@ const codec_entry f_codec_list[] = // instance of the given type //------------------------------------------------- -const codec_entry *find_in_list(chd_codec_type type) +const codec_entry *find_in_list(chd_codec_type type) noexcept { // find in the list and construct the class for (auto & elem : f_codec_list) @@ -668,7 +668,7 @@ chd_decompressor::ptr chd_codec_list::new_decompressor(chd_codec_type type, chd_ // corresponds to a supported codec //------------------------------------------------- -bool chd_codec_list::codec_exists(chd_codec_type type) +bool chd_codec_list::codec_exists(chd_codec_type type) noexcept { // find in the list and construct the class return bool(find_in_list(type)); @@ -680,7 +680,7 @@ bool chd_codec_list::codec_exists(chd_codec_type type) // codec //------------------------------------------------- -const char *chd_codec_list::codec_name(chd_codec_type type) +const char *chd_codec_list::codec_name(chd_codec_type type) noexcept { // find in the list and construct the class const codec_entry *entry = find_in_list(type); diff --git a/src/lib/util/chdcodec.h b/src/lib/util/chdcodec.h index c3234ea600d..08235ecaae6 100644 --- a/src/lib/util/chdcodec.h +++ b/src/lib/util/chdcodec.h @@ -104,8 +104,8 @@ public: static chd_decompressor::ptr new_decompressor(chd_codec_type type, chd_file &file); // utilities - static bool codec_exists(chd_codec_type type); - static const char *codec_name(chd_codec_type type); + static bool codec_exists(chd_codec_type type) noexcept; + static const char *codec_name(chd_codec_type type) noexcept; }; diff --git a/src/mame/igs/igs_m027.cpp b/src/mame/igs/igs_m027.cpp index 20f501b78fa..90fe92e16a8 100644 --- a/src/mame/igs/igs_m027.cpp +++ b/src/mame/igs/igs_m027.cpp @@ -3099,7 +3099,7 @@ GAME( 2003, mgzz100cn, mgzz, mgzz, mgzz100cn, igs_m027_stat GAME( 2007, mgcs3, 0, lhzb4, mgcs3, igs_m027_state, init_mgcs3, ROT0, "IGS", "Manguan Caishen 3 (V101CN)", 0 ) GAMEL( 1999, oceanpar, 0, oceanpar, oceanpar105us, igs_m027_state, init_oceanpar, ROT0, "IGS", "Ocean Paradise (V105US)", 0, layout_oceanpar ) // 1999 copyright in ROM GAMEL( 1999, oceanpar101us, oceanpar, oceanpar, oceanpar101us, igs_m027_state, init_oceanpar, ROT0, "IGS", "Ocean Paradise (V101US)", 0, layout_oceanpar ) // 1999 copyright in ROM -GAMEL( 1999, fruitpar, 0, oceanpar, oceanpar105us, igs_m027_state, init_fruitpar, ROT0, "IGS", "Fruit Paradise (V214)", 0, layout_oceanpar ) +GAMEL( 1999, fruitpar, 0, oceanpar, oceanpar105us, igs_m027_state, init_fruitpar, ROT0, "IGS", "Fruit Paradise (V214US)", 0, layout_oceanpar ) GAMEL( 1999, fruitpar206us, fruitpar, oceanpar, fruitpar206us, igs_m027_state, init_fruitpar, ROT0, "IGS", "Fruit Paradise (V206US)", 0, layout_oceanpar ) GAME( 200?, cjddz, 0, cjddz, cjddz, igs_m027_state, init_cjddz, ROT0, "IGS", "Chaoji Dou Dizhu (V215CN)", 0 ) GAME( 200?, cjddzp, 0, cjddz, cjddzp, igs_m027_state, init_cjddzp, ROT0, "IGS", "Chaoji Dou Dizhu Jiaqiang Ban (S300CN)", MACHINE_NODEVICE_LAN ) diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp index 639aec22a12..c71ed2a76e8 100644 --- a/src/tools/chdman.cpp +++ b/src/tools/chdman.cpp @@ -1765,8 +1765,10 @@ static void do_verify(parameters_map ¶ms) // fix it if requested; this also fixes the overall one so we don't need to do any more if (params.find(OPTION_FIX) != params.end()) { - input_chd.set_raw_sha1(computed_sha1); - util::stream_format(std::cout, "SHA-1 updated to correct value in input CHD\n"); + std::error_condition err = input_chd.set_raw_sha1(computed_sha1); + if (err) + report_error(1, "Error updating SHA1: %s", err.message()); + util::stream_format(std::cout, "SHA1 updated to correct value in input CHD\n"); } } else @@ -1788,7 +1790,10 @@ static void do_verify(parameters_map ¶ms) if (params.find(OPTION_FIX) != params.end()) { input_chd.set_raw_sha1(computed_sha1); - util::stream_format(std::cout, "SHA-1 updated to correct value in input CHD\n"); + std::error_condition err = input_chd.set_raw_sha1(computed_sha1); + if (err) + report_error(1, "Error updating SHA1: %s", err.message()); + util::stream_format(std::cout, "SHA1 updated to correct value in input CHD\n"); } } }