From 2b43e7f8f8095cd310bb19c51079fe7159aa5f34 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Tue, 27 Apr 2021 11:24:46 +0200 Subject: [PATCH] Avoid potential wrong memory access If the user uses an invalid index, the [] operator won't check it and the program will access invalid memory. Using at() would throw instead. --- gtsam/inference/FactorGraph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/inference/FactorGraph.h b/gtsam/inference/FactorGraph.h index 2bc9578b2..9d2308d9b 100644 --- a/gtsam/inference/FactorGraph.h +++ b/gtsam/inference/FactorGraph.h @@ -355,7 +355,7 @@ class FactorGraph { /** delete factor without re-arranging indexes by inserting a nullptr pointer */ - void remove(size_t i) { factors_[i].reset(); } + void remove(size_t i) { factors_.at(i).reset(); } /** replace a factor by index */ void replace(size_t index, sharedFactor factor) { at(index) = factor; }