schellingb / TinySoundFont

SoundFont2 synthesizer library in a single C/C++ file
MIT License
608 stars 71 forks source link

Fix TSF_MALLOC/TSF_REALLOC return values not checked for success [high conflict potential] #67

Closed ell1e closed 2 years ago

ell1e commented 2 years ago

This is my first shot at making sure TSF_MALLOC and TSF_REALLOC are being checked for allocation failure. Some functions return int instead of void now, to pass on the resulting allocation failure. This is not very well tested, at least not for actual out of memory cases. I'll need to think about how to test this best.

Fixes #61

ell1e commented 2 years ago

Okay, I think the conflict merge should have worked. Runs again in local test.

ell1e commented 2 years ago

Additional note: this also implements this suggestion to remove the outputSamples allocation entirely, such that the render functions can remain void with no need to report allocation failure.

schellingb commented 2 years ago

Thanks a lot for all the work on this PR!

After the merge I did some basic C89 fixes so it compiles in MSVC 6.0 again as well as some style cleanup - I hope you don't mind.

If you could look through that change e86d986 I'd be grateful. I fixed the if in tsf_load_samples and added cleanup in tsf_load_presets if malloc starts failing midway through. I think this covers all cases?

ell1e commented 2 years ago

Nice catch regarding the cleanup in tsf_load_presets I missed! The changes look good, I also like the configurable render size a lot. Cool to see this fix go in so fast :+1: