From 289928a17020cd11cdd22fdb2b262db00d969ad8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 28 May 2018 19:32:40 -0700 Subject: [PATCH] Sas: Correct calculation of VAG end. Not sure why everything is negative one indexed, but this prevents reading beyond the size of the buffer. This shouldn't change sound output, but it may fix a crash if VAG is at the edge of memory (unlikely, though.) --- Core/HW/SasAudio.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index ef33012dbeef..2758759f2d76 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -65,6 +65,11 @@ void VagDecoder::Start(u32 data, u32 vagSize, bool loopEnabled) { } void VagDecoder::DecodeBlock(u8 *&read_pointer) { + if (curBlock_ == numBlocks_ - 1) { + end_ = true; + return; + } + u8 *readp = read_pointer; int predict_nr = *readp++; int shift_factor = predict_nr & 0xf; @@ -106,9 +111,6 @@ void VagDecoder::DecodeBlock(u8 *&read_pointer) { s_2 = s2; curSample = 0; curBlock_++; - if (curBlock_ == numBlocks_) { - end_ = true; - } read_pointer = readp; }