From 8a7625e84205a066b97df5f3618326dae4672983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Braga?= Date: Tue, 21 May 2024 00:31:10 +0100 Subject: [PATCH 1/2] DUNE/Utils/String: avoid memory underflow if string empty --- src/DUNE/Utils/String.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DUNE/Utils/String.cpp b/src/DUNE/Utils/String.cpp index de8ab4de84..ec9d8a49de 100644 --- a/src/DUNE/Utils/String.cpp +++ b/src/DUNE/Utils/String.cpp @@ -82,7 +82,13 @@ namespace DUNE void String::rightTrimInPlace(char* str) { - char* r = str + std::strlen(str) - 1; // Rightmost character + const auto len = std::strlen(str); + + // smaller than two characters, nothing to trim + if (len < 2) + return; + + char* r = str + len - 1; // Rightmost character for (; isspace(*r); --r) *r = 0; From f28c647d0a2d5811e52e1a11015c01c74e35e26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Braga?= Date: Tue, 21 May 2024 00:31:31 +0100 Subject: [PATCH 2/2] Simulators/VSIM: proper size array --- src/Simulators/VSIM/Factory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulators/VSIM/Factory.cpp b/src/Simulators/VSIM/Factory.cpp index 5bae16a508..cb1d33834d 100644 --- a/src/Simulators/VSIM/Factory.cpp +++ b/src/Simulators/VSIM/Factory.cpp @@ -147,7 +147,7 @@ namespace Simulators double force[3]; double position[3]; - double orientation[2]; + double orientation[3]; // Retrieve fins. unsigned fins;