Fixes segfault for least squares problems with SPQR
As suggested by @markus.blatt, this MR will replace !487 (closed) by keeping only the changes that solve the bug when solving least squares problems with SPQR. The remaining changes proposed in !487 (closed) will be incorporated in a future MR.