the toolchain I use is Clion MinGW Bundle
the original code was generated by matlab
Why SIGTRAP occured when tried to allocate memory?
#define CODER_NEW(T, N) new T[N]
void reserve(SZ _n) {
if (_n > capacity_) {
T* const new_data{CODER_NEW(T, _n)}; //problem occur
(void)std::copy(data_, data_ + size_, new_data);
if (owner_) {
CODER_DELETE(data_);
}
data_ = new_data;
capacity_ = _n;
owner_ = true;
}
}


Here is a simple matlab function
It dynamically increase the size of array. I write this code so that coder cannot guess what size of array will return. Then I use coder to generate C++ code and use following code to call
test(int num, coder::array<int, 2U> &array). Guess what, It crashed.Let's see what happened inside this function.
First, it allocate memory is size of num. Then it write data to array. The problem here is that it didn't really check index outbound or not. The real problem here is that array coder produce unlike stl vector is not memory safe. Coder does not write data before check memory outbound.