[MAT-441] fix segfault from overflowing loop.

This patches the overflowing loop bound in pinv(). Also fixes up
the behaviour of pinv() in the case where the argument matrix is
all zeros.