diff options
author | 2025-05-02 14:31:22 +0200 | |
---|---|---|
committer | 2025-05-02 14:32:01 +0200 | |
commit | 2125d438b10cad74e846abc987bf1ba7821d2b94 (patch) | |
tree | ef34f7c39174e2717386cd47c81776eabc352e8b | |
parent | 607986d2876657821b3866dee938a67dd117de4e (diff) |
netlist: prevent stream buffer overflow after detecting it
-rw-r--r-- | src/devices/machine/netlist.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index c9d91704cce..8d4d6cedf4d 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -33,7 +33,6 @@ #define LOG_TIMING (1U << 3) //#define LOG_MASK (LOG_GENERAL | LOG_DEV_CALLS | LOG_DEBUG) -//#define LOG_MASK (LOG_TIMING) #define LOG_MASK (0) #define LOGDEVCALLS(...) LOGMASKED(LOG_DEV_CALLS, __VA_ARGS__) @@ -815,11 +814,15 @@ void netlist_mame_stream_output_device::device_reset() void netlist_mame_stream_output_device::sound_update_fill(sound_stream &stream, int output) { - if (stream.samples() < m_buffer.size()) - osd_printf_warning("sound %s: samples %d less bufsize %d\n", name(), stream.samples(), m_buffer.size()); + int samples = m_buffer.size(); + if (stream.samples() < samples) + { + osd_printf_warning("sound %s: samples %d less bufsize %d\n", name(), stream.samples(), samples); + samples = stream.samples(); + } int sampindex; - for (sampindex = 0; sampindex < m_buffer.size(); sampindex++) + for (sampindex = 0; sampindex < samples; sampindex++) stream.put(output, sampindex, m_buffer[sampindex]); if (sampindex < stream.samples()) stream.fill(output, m_cur, sampindex); @@ -858,7 +861,7 @@ void netlist_mame_stream_output_device::process(netlist::netlist_time_ext tim, n int pos = (tim - m_last_buffer_time) / m_sample_time; //if (pos > m_bufsize) // throw emu_fatalerror("sound %s: pos %d exceeded bufsize %d\n", name().c_str(), pos, m_bufsize); - while (m_buffer.size() < pos ) + while (m_buffer.size() < pos) { m_buffer.push_back(static_cast<sound_stream::sample_t>(m_cur)); } |