From f9fff3f9d860df808a4ce8277fa31f958ba90020 Mon Sep 17 00:00:00 2001
From: Romain BERNARD <romain.bernard@uca.fr>
Date: Tue, 17 Sep 2024 17:05:16 +0200
Subject: [PATCH] null safety in change lists

---
 src/routes/vehicle/propagation/SAEVRouteChangelist.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp b/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp
index d2e0885..535941b 100644
--- a/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp
+++ b/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp
@@ -21,7 +21,8 @@ void SAEVRouteChangelist::emplace_back(SAEVKeyPoint &kp, Bound bound, uint value
 }
 
 void SAEVRouteChangelist::applyChanges() {
-    if(_status < InsertionStatus::FAILURE_PRECONDITION_TW) {
+    if(_requestOriginKeyPoint != nullptr && _originPredecessorKP != nullptr
+    && _destinationPredecessorKP != nullptr && _status < InsertionStatus::FAILURE_PRECONDITION_TW) {
         _routePtr->insertRequest(*_requestOriginKeyPoint, _originPredecessorKP, _destinationPredecessorKP);
     }
     for(SAEVRouteChange change : _changelist) {
@@ -31,7 +32,8 @@ void SAEVRouteChangelist::applyChanges() {
 }
 
 void SAEVRouteChangelist::revertChanges() {
-    if(_status < InsertionStatus::FAILURE_PRECONDITION_TW) {
+    if(_requestOriginKeyPoint != nullptr && _originPredecessorKP != nullptr
+    && _destinationPredecessorKP != nullptr && _status < InsertionStatus::FAILURE_PRECONDITION_TW) {
         _routePtr->removeRequest(*_requestOriginKeyPoint);
     }
     for(SAEVRouteChange change : _changelist) {
-- 
GitLab