The Jc vector has n+1 elements, where n is the number of columns. Moreover, the size passed to memset() was wrong.