Hi Andreas,
> I am stuck: a generally working C PNG encoder segfaults for a particular file and I have no idea why. The C code is below, the MALLOC fails with message:
>
> malloc(): corrupted top size
most probable problem: Your bindings are wrong. If you screw up the
signature, you'll get wrong stack setup and that might crash with the
heap.
> Now I would love to know what exactly I try to maloc for my example so I inserted some printfs. But nothing is printed out and I have not idea why?
Most probably, because the code you modify is not the code you build. I
used the "just printf what you want to know"-method in the past with
JNA and it worked.
You might want to check how you call your programm, as the environment
might redirect stdout. I faced this problem in combination with junit
tests and had to change the build script to pass through the output.
>
> EXPORT ByteArray* fpng_encode_image_to_memory(const void* pImage, uint32_t w, uint32_t h, uint32_t num_chans, uint32_t flags = 0)
The last argument looks broken. C (to my knowledge) does not allow
overloaded calls and even if it would allow them, it would raise the
question how they are realized.
In the end JNA/libffi setup the stack and jump to the function, for
this they need to know how the stack has to look before jumping and
they have to know where. If the name is not unique, I don't see how
this should work.
Greetings
Matthias