From 82425f20d7ca9ffa8789ca68e5e82cd16a8d8af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 26 Jun 2022 21:58:04 +0200 Subject: [PATCH] Handle `WavpackUnpackSamples` failure --- src/engine/client/sound.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp index 47cadfd27..40f930fe3 100644 --- a/src/engine/client/sound.cpp +++ b/src/engine/client/sound.cpp @@ -533,7 +533,12 @@ int CSound::DecodeWV(int SampleID, const void *pData, unsigned DataSize) } int *pBuffer = (int *)calloc((size_t)NumSamples * NumChannels, sizeof(int)); - WavpackUnpackSamples(pContext, pBuffer, NumSamples); // TODO: check return value + if(!WavpackUnpackSamples(pContext, pBuffer, NumSamples)) + { + free(pBuffer); + dbg_msg("sound/wv", "WavpackUnpackSamples failed. NumSamples=%d, NumChannels=%d", NumSamples, NumChannels); + return -1; + } int *pSrc = pBuffer; pSample->m_pData = (short *)calloc((size_t)NumSamples * NumChannels, sizeof(short));