for (size_t i = 0; i < length; i++) { size_t j = (length - 1) - i; ... }
Makes my brain hurt, but I think this will only run through the loop one time looking at the last element of the array.
const j = (length - 1) - i;