summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-08-23 07:56:48 -0400
committer Nathan Woods <npwoods@mess.org>2016-08-23 07:56:48 -0400
commit846cd43287687f3d4ed7dc55a7e65f6eb33d0e15 (patch)
tree45cd2cd01286295bed8a3f35dc6520a83d1ce7eb /src/lib
parentd64c4c6b6cc7587b88c55fc175e2e63e583f66d2 (diff)
Performs argument checking on the return value of CassetteLegacyWaveFiller.chunk_sample_calc()
This is just better error checking. You can see this if you create a garbage file named 'foo.csw' and invoke the following command: mame bbcb -cass1 foo.csw With this change you get an invalid image error. Without it, you get this: Caught unhandled St12length_error exception: vector::_M_default_append
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/formats/cassimg.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/formats/cassimg.cpp b/src/lib/formats/cassimg.cpp
index 50d653cbe5d..58add1aaed0 100644
--- a/src/lib/formats/cassimg.cpp
+++ b/src/lib/formats/cassimg.cpp
@@ -903,7 +903,7 @@ cassette_image::error cassette_legacy_construct(cassette_image *cassette,
chunk.resize(args.chunk_size);
/* determine number of samples */
- if (args.chunk_sample_calc)
+ if (args.chunk_sample_calc != nullptr)
{
if (size > 0x7FFFFFFF)
{
@@ -914,6 +914,13 @@ cassette_image::error cassette_legacy_construct(cassette_image *cassette,
bytes.resize(size);
cassette_image_read(cassette, &bytes[0], 0, size);
sample_count = args.chunk_sample_calc(&bytes[0], (int)size);
+
+ // chunk_sample_calc functions report errors by returning negative numbers
+ if (sample_count < 0)
+ {
+ err = cassette_image::error::INVALID_IMAGE;
+ goto done;
+ }
if (args.header_samples < 0)
args.header_samples = sample_count;