romeric/Fastor

Heap allocation in debug builds due to FASTOR_EXIT_ASSERT macro

Closed this issue · 1 comments

Hi,

we shortly decided to use fastor in the context of an real-time-appication.
We stumbled across the fact that in debug builds heap is regulary allocated and freed.
The issue could relatively fast be tracked to the following function referenced in the FASTOR_ASSERT makro in macros.h.

FASTOR_INLINE void FASTOR_EXIT_ASSERT(bool cond, const std::string &msg="") {
if (cond==false) {
throw std::runtime_error(msg);
}
}

The heap allocation results due to the fact, that providing a const char* argument to the function leads to the construction of an std::string. Which in my opinion unintentionally leads to an heap allocation.

It looks like its relatively easy fixable by exchanging const std::sting& with const char* since std::runtime_error supports both types.

I wanted to provide an pull request but stumbled on the fact that the FASTOR_ASSERT makro is also used in the unit tests. In my opinion the best way would be to provide a different makro for the unittests to avoid unintentionally using std::string and therby heap. You can find my fork using the following link. ATM I just defined a second Version of the Function and removed the parameter default fromt the string variant to avoid ambuguity.

master...Forlautboy:Fastor_no_malloc_in_assert:master

Greetings,

Tobias

07617c5 fixes this issue. There is now a unittest specific macro FASTOR_DOES_CHECK_PASS. std::string has been replaced by char* in all assertion macros.

Thank you for reporting the issue.