From 1de0a9544d09f3f0a7c9682ae97adb899e526ee1 Mon Sep 17 00:00:00 2001 From: Clement Courbet Date: Mon, 25 Aug 2025 13:44:15 +0000 Subject: [PATCH 1/2] Fix out-of-bound access in `clean_up_infeasibilities`. This OOB access happens when the last element is the one being removed: the second access to `infeasibility_indices[k]` after the `pop_back` is invalid. This is another example for issue #150. Signed-off-by: Clement Courbet --- cpp/src/dual_simplex/phase2.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cpp/src/dual_simplex/phase2.cpp b/cpp/src/dual_simplex/phase2.cpp index 76f4768abd..6d5adb5f7c 100644 --- a/cpp/src/dual_simplex/phase2.cpp +++ b/cpp/src/dual_simplex/phase2.cpp @@ -752,10 +752,9 @@ void clean_up_infeasibilities(std::vector& squared_infeasibilities, const f_t squared_infeas = squared_infeasibilities[j]; if (squared_infeas == 0.0) { // Set to the last element - const i_t sz = infeasibility_indices.size(); - infeasibility_indices[k] = infeasibility_indices[sz - 1]; + const i_t new_j = infeasibility_indices.back(); + infeasibility_indices[k] = new_j; infeasibility_indices.pop_back(); - i_t new_j = infeasibility_indices[k]; if (squared_infeasibilities[new_j] == 0.0) { k--; } } } From 9e81244b9685f0842bba2aa6e8e294ea31c74166 Mon Sep 17 00:00:00 2001 From: Ramakrishnap <42624703+rgsl888prabhu@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:15:42 -0500 Subject: [PATCH 2/2] Update phase2.cpp --- cpp/src/dual_simplex/phase2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/dual_simplex/phase2.cpp b/cpp/src/dual_simplex/phase2.cpp index 6d5adb5f7c..7383f42216 100644 --- a/cpp/src/dual_simplex/phase2.cpp +++ b/cpp/src/dual_simplex/phase2.cpp @@ -752,7 +752,7 @@ void clean_up_infeasibilities(std::vector& squared_infeasibilities, const f_t squared_infeas = squared_infeasibilities[j]; if (squared_infeas == 0.0) { // Set to the last element - const i_t new_j = infeasibility_indices.back(); + const i_t new_j = infeasibility_indices.back(); infeasibility_indices[k] = new_j; infeasibility_indices.pop_back(); if (squared_infeasibilities[new_j] == 0.0) { k--; }