mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Handle failure of op_pcm_total
function
According to the documentation, this function returns `0` on success and a negative number (error code) otherwise, which would cause an allocation of an invalid size.
This commit is contained in:
parent
d0e27fdcd4
commit
d06f6d3370
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue