From 7e1fd3f287d5ccd375d142f4baaf3ec2646de70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Mon, 17 Feb 2025 15:52:14 +0100 Subject: [PATCH 1/2] Fix std::bad_array_new_length exception in SurveyResults::SurveyResults (#2643) This happens only if there is at least one area and no output variables (example study valid-filter-outputs/no-geo-trim--noVar) The original code is equivalent to ```cpp bool* x = new bool[0]{false}; ``` which throws a `std::bad_array_new_length` exception as shown [here](https://en.cppreference.com/w/cpp/memory/new/bad_array_new_length). --- .../variable/surveyresults/surveyresults.cpp | 6 +- src/tests/src/solver/variable/CMakeLists.txt | 6 ++ .../solver/variable/test_surveyresults.cpp | 56 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/tests/src/solver/variable/test_surveyresults.cpp diff --git a/src/solver/variable/surveyresults/surveyresults.cpp b/src/solver/variable/surveyresults/surveyresults.cpp index cb88d34003..552e205d61 100644 --- a/src/solver/variable/surveyresults/surveyresults.cpp +++ b/src/solver/variable/surveyresults/surveyresults.cpp @@ -558,7 +558,11 @@ SurveyResults::SurveyResults(const Data::Study& s, const Yuni::String& o, IResul digestNonApplicableStatus = new bool*[digestSize]; for (uint i = 0; i < digestSize; i++) { - digestNonApplicableStatus[i] = new bool[maxVariables]{false}; + digestNonApplicableStatus[i] = new bool[maxVariables]; + for (uint var = 0; var != maxVariables; ++var) + { + digestNonApplicableStatus[i][var] = false; + } } } diff --git a/src/tests/src/solver/variable/CMakeLists.txt b/src/tests/src/solver/variable/CMakeLists.txt index f06cb7ee2e..d068bea6dc 100644 --- a/src/tests/src/solver/variable/CMakeLists.txt +++ b/src/tests/src/solver/variable/CMakeLists.txt @@ -3,3 +3,9 @@ include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) add_boost_test(test-intermediate SRC test_intermediate.cpp LIBS antares-solver-variable) + +add_boost_test(test-surveyresults + SRC test_surveyresults.cpp + LIBS + antares-solver-variable + result_writer) diff --git a/src/tests/src/solver/variable/test_surveyresults.cpp b/src/tests/src/solver/variable/test_surveyresults.cpp new file mode 100644 index 0000000000..e6c5c78edc --- /dev/null +++ b/src/tests/src/solver/variable/test_surveyresults.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ +#define BOOST_TEST_MODULE "test time series" + +#define WIN32_LEAN_AND_MEAN + +#include + +#include "antares/solver/variable/surveyresults.h" +#include "antares/writer/in_memory_writer.h" + +using namespace Antares::Solver::Variable; + +struct StudyFixture +{ + StudyFixture(): + study(std::make_unique()) + { + study->parameters.simulationDays.first = 0; + study->parameters.simulationDays.end = 7; + study->initializeRuntimeInfos(); + } + + std::unique_ptr study; +}; + +BOOST_AUTO_TEST_SUITE(surveyresults) + +BOOST_FIXTURE_TEST_CASE(no_variable_constructor_does_not_throw, StudyFixture) +{ + Benchmarking::DurationCollector durationCollector; + Antares::Solver::InMemoryWriter writer(durationCollector); + // At least one area was required to trigger a std::bad_alloc throw + Antares::Data::addAreaToListOfAreas(study->areas, "dummyArea"); + BOOST_CHECK_NO_THROW(SurveyResults survey(*study, "out", writer);); +} + +BOOST_AUTO_TEST_SUITE_END() From 8deb2e52e11454817ee6b4ea8ff01806bb98e173 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Tue, 18 Feb 2025 15:02:24 +0100 Subject: [PATCH 2/2] Bump simtest to 9.2.0k (#2644) --- simtest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simtest.json b/simtest.json index 60f2219bb7..e5346ead1e 100644 --- a/simtest.json +++ b/simtest.json @@ -1,3 +1,3 @@ { - "version": "v9.2.0i" + "version": "v9.2.0k" }