diff options
author | Vas Crabb <vas@vastheman.com> | 2021-12-09 17:46:53 +1100 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2021-12-09 17:46:53 +1100 |
commit | 28818fe34552afef3812fb1a6455201a3c132c09 (patch) | |
tree | 53be89b5e1cb60f5974b9feb2e0433022b6daae9 /src/emu | |
parent | a7d29a8294fe82d969f93ed03467c394505e7feb (diff) |
emu/mconfig.cpp: Made checks on device add/replace stricter.
Trying to replace a non-existent device or trying to add a device with
root or parent references in the path is now fatal. If you find
yourself wanting to do this, your design is probably broken.
Diffstat (limited to 'src/emu')
-rw-r--r-- | src/emu/mconfig.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/emu/mconfig.cpp b/src/emu/mconfig.cpp index fb97c3138a3..2c8c1aa011b 100644 --- a/src/emu/mconfig.cpp +++ b/src/emu/mconfig.cpp @@ -257,24 +257,23 @@ std::pair<const char *, device_t *> machine_config::resolve_owner(const char *ta device_t *owner(m_current_device); // if the device path is absolute, start from the root - if (tag[0] == ':') - { - tag++; - owner = m_root_device.get(); - } + if (!*tag || (':' == *tag) || ('^' == *tag)) + throw emu_fatalerror("Attempting to add device with tag containing parent references '%s'\n", orig_tag); // go down the path until we're done with it - while (strchr(tag, ':')) + char const *next; + while ((next = strchr(tag, ':')) != nullptr) { - const char *next = strchr(tag, ':'); assert(next != tag); std::string_view part(tag, next - tag); owner = owner->subdevices().find(part); if (!owner) - throw emu_fatalerror("Could not find %s when looking up path for device %s\n", part, orig_tag); - tag = next+1; + throw emu_fatalerror("Could not find '%s' when looking up path for device '%s'\n", part, orig_tag); + tag = next + 1; + if ('^' == *tag) + throw emu_fatalerror("Attempting to add device with tag containing parent references '%s'\n", orig_tag); } - assert(tag[0] != '\0'); + assert(*tag != '\0'); return std::make_pair(tag, owner); } @@ -296,7 +295,7 @@ std::tuple<const char *, device_t *, device_t *> machine_config::prepare_replace if (old_device) remove_references(*old_device); else - osd_printf_warning("Warning: attempting to replace non-existent device '%s'\n", tag); + throw emu_fatalerror("Attempting to replace non-existent device '%s'\n", tag); return std::make_tuple(owner.first, owner.second, old_device); } |