-imagedev/harddriv.cpp: Report unsuitable CHDs rather than crashing.

-imagedev/cdrom.cpp: Report unsuitable CHDs as "invalid image" rather
than "unsupported operation".
This commit is contained in:
Vas Crabb 2024-02-10 11:10:00 +11:00
parent 85c9517c69
commit a17ea8387c
2 changed files with 40 additions and 29 deletions

View File

@ -136,7 +136,7 @@ std::pair<std::error_condition, std::string> cdrom_image_device::call_load()
m_dvdrom_handle.reset(new dvdrom_file(chd));
else
{
err = image_error::UNSUPPORTED;
err = image_error::INVALIDIMAGE;
goto error;
}
}
@ -146,15 +146,15 @@ std::pair<std::error_condition, std::string> cdrom_image_device::call_load()
{
m_cdrom_handle.reset(new cdrom_file(filename()));
}
catch (void *)
catch (...)
{
try
{
m_dvdrom_handle.reset(new dvdrom_file(filename()));
}
catch (void *)
catch (...)
{
err = image_error::UNSUPPORTED;
err = image_error::INVALIDIMAGE;
goto error;
}
}

View File

@ -287,24 +287,31 @@ std::error_condition harddisk_image_device::internal_load_hd()
if (m_chd)
{
// open the hard disk file
try
{
m_hard_disk_handle.reset(new hard_disk_file(m_chd));
if (m_hard_disk_handle)
return std::error_condition();
}
else
catch (...)
{
if (is_open())
err = image_error::INVALIDIMAGE;
}
}
else if (!is_open())
{
err = image_error::UNSPECIFIED;
}
else
{
uint32_t skip = 0;
// check for 2MG format
if (!memcmp(header, "2IMG", 4))
if (!memcmp(header, "2IMG", 4)) // check for 2MG format
{
skip = get_u32le(&header[0x18]);
osd_printf_verbose("harddriv: detected 2MG, creator is %c%c%c%c, data at %08x\n", header[4], header[5], header[6], header[7], skip);
}
// check for HDI format
else if (is_filetype("hdi"))
else if (is_filetype("hdi")) // check for HDI format
{
skip = get_u32le(&header[0x8]);
uint32_t data_size = get_u32le(&header[0xc]);
@ -318,17 +325,21 @@ std::error_condition harddisk_image_device::internal_load_hd()
}
}
try
{
m_hard_disk_handle.reset(new hard_disk_file(image_core_file(), skip));
if (m_hard_disk_handle)
return std::error_condition();
}
return image_error::UNSPECIFIED;
catch (...)
{
err = image_error::INVALIDIMAGE;
}
}
/* if we had an error, close out the CHD */
m_origchd.close();
m_diffchd.close();
m_origchd.close();
m_chd = nullptr;
if (err)