Skip to content

Commit

Permalink
[sap] Avoid factoring ununitialized memory (#21430)
Browse files Browse the repository at this point in the history
Thanks, valgrind!

Also respell the initializer list helpers for clarity.
  • Loading branch information
jwnimmer-tri authored May 14, 2024
1 parent ad104f6 commit 216ac4c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions multibody/contact_solvers/sap/dense_supernodal_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ namespace multibody {
namespace contact_solvers {
namespace internal {

int SafeGetCols(const BlockSparseMatrix<double>* J) {
DRAKE_THROW_UNLESS(J != nullptr);
return J->cols();
}

template <typename T>
const T& SafeGetReference(std::string_view variable_name, const T* ptr) {
const T& SafeDeference(std::string_view variable_name, const T* ptr) {
if (ptr == nullptr) {
throw std::runtime_error(
fmt::format("Condition '{} != nullptr' failed.", variable_name));
Expand All @@ -23,9 +18,9 @@ const T& SafeGetReference(std::string_view variable_name, const T* ptr) {

DenseSuperNodalSolver::DenseSuperNodalSolver(
const std::vector<MatrixX<double>>* A, const BlockSparseMatrix<double>* J)
: A_(SafeGetReference("A", A)),
J_(SafeGetReference("J", J)),
H_(SafeGetCols(J), SafeGetCols(J)),
: A_(SafeDeference("A", A)),
J_(SafeDeference("J", J)),
H_(Eigen::MatrixXd::Zero(J->cols(), J->cols())),
Hldlt_(H_) {
const int nv = [this]() {
int size = 0;
Expand Down

0 comments on commit 216ac4c

Please sign in to comment.