Skip to content

Commit

Permalink
Fix segfault when trying to access some image option that does not ex…
Browse files Browse the repository at this point in the history
…ists (#5352)

* emuopts.h: Add method to check if image option exists

* image.cpp: Avoid to require image_option if it does not exists
  • Loading branch information
AmatCoder authored and rb6502 committed Jul 18, 2019
1 parent 7939bb9 commit a14ec2c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/emu/emuopts.h
Expand Up @@ -480,6 +480,7 @@ class emu_options : public core_options
bool has_slot_option(const std::string &device_name) const { return find_slot_option(device_name) ? true : false; }
const ::image_option &image_option(const std::string &device_name) const;
::image_option &image_option(const std::string &device_name);
bool has_image_option(const std::string &device_name) const { return m_image_options.find(device_name) != m_image_options.end(); }

protected:
virtual void command_argument_processed() override;
Expand Down
5 changes: 3 additions & 2 deletions src/emu/image.cpp
Expand Up @@ -196,7 +196,8 @@ void image_manager::options_extract()
// Note that as a part of #2, we cannot extract the option when the image in question is a part of an
// active reset_on_load; hence the check for is_reset_and_loading() (see issue #2414)
if (!image.is_reset_on_load()
|| (!image.exists() && !image.is_reset_and_loading() && !machine().options().image_option(image.instance_name()).value().empty()))
|| (!image.exists() && !image.is_reset_and_loading()
&& machine().options().has_image_option(image.instance_name()) && !machine().options().image_option(image.instance_name()).value().empty()))
{
// we have to assemble the image option differently for software lists and for normal images
std::string image_opt;
Expand All @@ -211,7 +212,7 @@ void image_manager::options_extract()
}

// and set the option (provided that it hasn't been removed out from under us)
if (machine().options().exists(image.instance_name()))
if (machine().options().exists(image.instance_name()) && machine().options().has_image_option(image.instance_name()))
machine().options().image_option(image.instance_name()).specify(std::move(image_opt));
}
}
Expand Down

0 comments on commit a14ec2c

Please sign in to comment.