From 79d3330a60e30ace228052fd8cb8f23857acb863 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Sat, 8 Jun 2024 17:41:52 +0300 Subject: imagedev/floppy.cpp: fix out-of-bounds access to the seek sample (#12452) Currently, when `floppy_sound_device::step` selects a new seek sample, the value of `m_seek_samplepos` remains the same as it was the last time a seek sample was played. This might be an invalid position for the new sample, since the seek samples have different lengths. When this is the case, the next call to `floppy_sound_device::sound_stream_update` makes an out-of-bounds memory access as it reads the sample data. Fix this by resetting `m_seek_samplepos` to 0 when a new seek sample is selected. This also makes the seek sounds more consistent, since previously they would start from a semi-random position each time. --- src/devices/imagedev/floppy.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index 76621ac95e0..de93d9d7815 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -1639,6 +1639,9 @@ void floppy_sound_device::step(int zone) } } } + + // Start the new seek sound from the beginning. + m_seek_samplepos = 0; } // Changing the pitch does not always sound convincing -- cgit v1.2.3