mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpilibc] Fix a use-after-free in DifferentialDrivetrainSim (#2741)
In the second constructor, a new LinearSystem is created and set to m_plant. This takes a const ref though, so it's storing a reference to a temporary object. After the constructor finishes, m_plant points to an invalid object. When Update() is called, it will crash with a segmentation fault. This patch fixes the use-after-free by making m_plant a LinearSystem value type. The first constructor will generate a copy, but that only happens once.
This commit is contained in:
@@ -203,7 +203,7 @@ class DifferentialDrivetrainSim {
|
||||
}
|
||||
|
||||
private:
|
||||
const LinearSystem<2, 2, 2>& m_plant;
|
||||
LinearSystem<2, 2, 2> m_plant;
|
||||
units::meter_t m_rb;
|
||||
units::meter_t m_wheelRadius;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user