diff -rupN ceres-solver-1.13.0/internal/ceres/compressed_row_sparse_matrix.cc ceres-solver-1.13.0-new/internal/ceres/compressed_row_sparse_matrix.cc --- ceres-solver-1.13.0/internal/ceres/compressed_row_sparse_matrix.cc 2017-08-03 09:10:55.000000000 +0200 +++ ceres-solver-1.13.0-new/internal/ceres/compressed_row_sparse_matrix.cc 2018-07-28 22:31:51.989682309 +0200 @@ -196,6 +196,11 @@ CompressedRowSparseMatrix* CompressedRow CompressedRowSparseMatrix* output = new CompressedRowSparseMatrix(num_rows, num_cols, input.num_nonzeros()); + if (num_rows == 0) { + // No data to copy. + return output; + } + // Copy the contents of the cols and values array in the order given // by index and count the number of entries in each row. int* output_rows = output->mutable_rows();