diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp index 9342ed57a..1ef64c204 100644 --- a/src/engine/client/sound.cpp +++ b/src/engine/client/sound.cpp @@ -346,8 +346,6 @@ bool CSound::DecodeOpus(CSample &Sample, const void *pData, unsigned DataSize) c if(pOpusFile) { const int NumChannels = op_channel_count(pOpusFile, -1); - const int NumSamples = op_pcm_total(pOpusFile, -1); // per channel! - if(NumChannels > 2) { op_free(pOpusFile); @@ -355,6 +353,14 @@ bool CSound::DecodeOpus(CSample &Sample, const void *pData, unsigned DataSize) c return false; } + const int NumSamples = op_pcm_total(pOpusFile, -1); // per channel! + if(NumSamples < 0) + { + op_free(pOpusFile); + dbg_msg("sound/opus", "failed to get number of samples, error %d", NumSamples); + return false; + } + short *pSampleData = (short *)calloc((size_t)NumSamples * NumChannels, sizeof(short)); int Pos = 0;