Your problem is in using unsigned int
. Look at this line:
for(j = J; j >= 0; j--)
Here, after j becomes 0, it gets decremented. But your j
is unsigned
, so instead of becoming -1
(and exiting the cycle on the next iteration), j
becomes 4158584613
, and the cycle continues, trying to access the obviously out-of-bonds element at index 4158584613
at this line:
(*current)[j] = 0;
Making i
, j
, and length
signed will solve your problem.