• Bugs
  • C Runtime: MALLOC() Bug

  • Изменено
Related Discussions
...

Hi!

There is a small but significant bug in extension.h of the C runtime:

#define MALLOC(TYPE,COUNT) ((TYPE*)_malloc(sizeof(TYPE) * COUNT, __FILE__, __LINE__))

This macro should be defined like this instead:

#define MALLOC(TYPE,COUNT) ((TYPE*)_malloc(sizeof(TYPE) * (COUNT), __FILE__, __LINE__))

Otherwise statements like...

spTimeline** timelines = MALLOC(spTimeline*, anim->timelinesCount + 1);

...will actually allocate anim->timelinesCount elements, plus 1 byte, rather than (anim->timelinesCount + 1) elements.

Obviously, a functional workaround is to parenthesize on each use, but this violates the principle of least surprise for most C programmers trying to extend the library. I hope this is helpful!

Cheers,


Tim A.

A good change, thank you! In Git now. 🙂