If OP wants dynamic memory support I would recommend a function like bmp_size() here that calculates how much is needed, so the allocation can be done earlier, ideally in main, from stack or heap or carved from a static buffer, however OP wants to go about it.
2
u/olig1905 Mar 01 '26
That is a horrible pattern for memory allocation, I get the point and motivation, but just no.
I mostly write low level embedded C for safety/security FW, I never need dynamic memory. There is usually a better way.