diff options
author | Chris Robinson <[email protected]> | 2023-01-15 19:18:31 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-01-15 19:20:34 -0800 |
commit | 8e9833c7a6dfe53b570d5a021888f2a5397b4796 (patch) | |
tree | f142787b050ab732b3691a69419e80fdac63ab24 /core | |
parent | ec2bea832ba137874f1d86407cf25400d6b8714f (diff) |
Check for nullptr before constructing a new object
Diffstat (limited to 'core')
-rw-r--r-- | core/hrtf.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/core/hrtf.cpp b/core/hrtf.cpp index 3a5d580b..d5c7573a 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -388,12 +388,10 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(uint rate, uint8_t irSize, total += sizeof(std::declval<HrtfStore&>().mCoeffs[0])*irCount; total += sizeof(std::declval<HrtfStore&>().mDelays[0])*irCount; - void *ptr{al_calloc(16, total)}; - std::unique_ptr<HrtfStore> Hrtf{al::construct_at(static_cast<HrtfStore*>(ptr))}; - if(!Hrtf) - ERR("Out of memory allocating storage for %s.\n", filename); - else + std::unique_ptr<HrtfStore> Hrtf{}; + if(void *ptr{al_calloc(16, total)}) { + Hrtf.reset(al::construct_at(static_cast<HrtfStore*>(ptr))); InitRef(Hrtf->mRef, 1u); Hrtf->mSampleRate = rate; Hrtf->mIrSize = irSize; @@ -432,6 +430,8 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(uint rate, uint8_t irSize, Hrtf->mCoeffs = coeffs_; Hrtf->mDelays = delays_; } + else + ERR("Out of memory allocating storage for %s.\n", filename); return Hrtf; } |