Potential Memory access problem in sim_lifted_irk_integrator.c

Hi All,

I am new to acados which I think is an excellent OCP solver. I use C interface and use lifted_irk for the dynamic of my OCP.
Following the examples, I used python to generate the C code external function first and then construct the OCP in C.
But the program may report error of
“type in XXX”
“Unknown external function argument type for argument 4”
“XXX” is often a random large value. And the program exit.

I check the number of the external dynamic function input is 6 (which means in_num == 6). But I found that the following code
“for (ii = 0; ii < fun->in_num - 1; ii++)”
in external_function_param_casadi_wrapper will loop ii = 0 to ii = 4. But, the input “type_in” array is passed from the function defined in acados/sim/sim_lifted_irk_integrator.c with only size 4:
" ext_fun_arg_t ext_fun_type_in[4];"

Then, it looks like that the code will try to access ext_fun_type_in[4] which may return a random value.
I try to change the code to
ext_fun_arg_t ext_fun_type_in[5];
void *ext_fun_in[4];
// TODO: fix this for z
ext_fun_type_in[3] = COLMAJ;
ext_fun_type_in[4] = COLMAJ;
Look like it works well now.
Is it really a bug? Or I make some mistakes in constructing the OCP? Is my way a correct way to fix this problem?
Thank you for your help.



did you use the same acados version and installation for both, creating the C functions and running the test.
I checked, this example uses LIFTED IRK and work fine https://github.com/FreyJo/acados/blob/1e196fd7533dddf3ba24ebca0eb9aa0c982276b9/examples/acados_python/pendulum_on_cart/ocp/nonuniform_discretization_example.py

Does it work for you too?

Dear FreyJo:

Thank you for your reply. I try to run the example and it works fine.
The acados version for running my C code and the example is the same. And for my another C function, it also works fine.
I try to debug the case that works fine, and I found that ext_fun_type_in[4] is always a meaningful value though index 4 is outside the size of the array.
But for my another C function, ext_fun_type_in[4] always return a very random large value. I think it is a determinsitc problem?
But if the input size of the external casadi function is 6, then for the code now it exceeds the array size. Is this input size 6 a correct size?

Thank you for your help.