libcg / gLib2D

A simple, fast, light-weight 2D graphics library for PSP.
GNU Lesser General Public License v3.0
46 stars 12 forks source link

Library does not check return values for malloc and realloc calls #5

Open evanbowman opened 3 years ago

evanbowman commented 3 years ago

Thank you for your work on this library. I just wanted to raise a minor issue I ran into, where some code that I was playing around with crashed, due to a failed malloc call on the initial dlist allocation. As the library context is created on the fly after the first call of one of the library routines, I'm not sure of the best way to communicate allocation failures to library users. In my case, the dlist allocation failed, causing an invalid read and a corresponding crash after the first call to g2dClear(), which returns void.

Anyway, I ended up working around the problem by editing the library code to use a global static buffer for the dlist memory, so it's not an urgent issue for me.

VerMishelb commented 2 years ago

malloc() fails and returns NULL to dlist if you have BUILD_PRX = 1 in Makefile when building your project. Even though others said that I can't use PBP without PRX on the real hardware it seems to work (with CFW), but I still don't understand why wouldn't malloc() work and I don't know enough about both C and PSP to fix this. UPD: Updating to the latest pspsdk solved the issue.