lf-lang / reactor-c

A reactor runtime written in C
Other
12 stars 24 forks source link

Memory error in trace buffer initialization #451

Open cmnrd opened 4 months ago

cmnrd commented 4 months ago

When I compile the RTI (using gcc 14), then I get the following error:

/home/cmenard/projects/lf/lingua-franca/core/src/main/resources/lib/c/reactor-c/trace/impl/src/trace_impl.c: In function ‘start_trace’:
/home/cmenard/projects/lf/lingua-franca/core/src/main/resources/lib/c/reactor-c/trace/impl/src/trace_impl.c:155:57: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  155 |   trace->_lf_trace_buffer_size = (size_t*)calloc(sizeof(size_t), trace->_lf_number_of_trace_buffers + 1);
      |                                                         ^~~~~~
/home/cmenard/projects/lf/lingua-franca/core/src/main/resources/lib/c/reactor-c/trace/impl/src/trace_impl.c:155:57: note: earlier argument should specify number of elements, later size of each element

This hints at a bug in https://github.com/lf-lang/reactor-c/blob/587a8f9498b69bc82f404e432f881d7bb0bcf383/trace/impl/src/trace_impl.c#L155, which seems to have transposed arguments for the call to calloc.

I wanted to push a simple fix, but then I realized that there are more strange artifacts around this code. In particular:

petervdonovan commented 4 months ago

Since this is a potential bug in the version of tracing that saves traces to local binary files, it is not a blocker for anything that has a specific deadline. Therefore, I am giving it low priority.