dvidelabs / flatcc

FlatBuffers Compiler and Library in C for C
Apache License 2.0
653 stars 189 forks source link

_portable_aligned_alloc not returning as expected when malloc is unsuccessful #269

Closed edlongman closed 1 year ago

edlongman commented 1 year ago

I am am compiling and running flatcc on a dsPIC using the XC16 compiler and generally having success with very minor tweaks.

When calling finalize_aligned_buffer it uses the __portable_aligned_alloc implementation but when malloc cannot assign the space and it returns nullptr, the alloc does not, instead returning 4

image

Perhaps there should be a check here to see if malloc fails

mikkelfj commented 1 year ago

You are right, I don't know what I was thinking. Fixed in https://github.com/dvidelabs/flatcc/commit/b2125775fdec2f5a4cba7ad569ea0186adf45e70

I plan to make a release soon, so it will be in there.

mikkelfj commented 1 year ago

I also fixed FLATCC_ALIGNED_ALLOC which is used when you are not able to use malloc. https://github.com/dvidelabs/flatcc/commit/6c3fe816205e25487d5320e755f91080bc57621b

edlongman commented 1 year ago

Thanks, I didn't need it to work as I didn't need the aligned alloc it just so happened that I stumbled upon it because of a misconfiguration of my heap size as well as using finalize_aligned