You are using the C99 variable length array feature to define the size of end_matrix
. Unfortunately, row_num
and col_num
are both zero, meaning neither “dimension” has any storage allocated. When you attempt to write into the array, because no storage was reserved for it, you are writing past the end and triggering undefined behavior that is manifesting as a segfault.
It looks like you have row_max
and col_max
defined as constants; perhaps you meant to use those instead of row_num
and col_num
when defining end_matrix
.