Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential access violation #2278

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions src/solver/constraints-builder/cbuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
** 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 <https://opensource.org/license/mpl-2-0/>.
*/
* 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 <https://opensource.org/license/mpl-2-0/>.
*/

#include "antares/solver/constraints-builder/cbuilder.h"

Expand Down Expand Up @@ -54,15 +54,6 @@ CBuilder::CBuilder(Antares::Data::Study& study):
{
}

CBuilder::~CBuilder()
{
// delete all the elements of pLink
for (auto i = pLink.begin(); i != pLink.end(); i++)
{
delete *i;
}
}

bool Antares::CBuilder::isCycleDriver(linkInfo* lnkI)
{
std::string s1(lnkI->ptr->from->name.to<std::string>());
Expand Down Expand Up @@ -180,7 +171,7 @@ bool CBuilder::updateLinks()
}

// check validity of loopflow against NTC
if (includeLoopFlow && !checkValidityOfNodalLoopFlow(linkInfo, hour))
if (includeLoopFlow && !checkValidityOfNodalLoopFlow(linkInfo.get(), hour))
{
return false;
}
Expand All @@ -190,8 +181,8 @@ bool CBuilder::updateLinks()
continue;
}

updateLinkPhaseShift(linkInfo, hour);
if (!checkLinkPhaseShift(linkInfo, hour))
updateLinkPhaseShift(linkInfo.get(), hour);
if (!checkLinkPhaseShift(linkInfo.get(), hour))
{
return false;
}
Expand Down Expand Up @@ -239,7 +230,7 @@ bool CBuilder::update()
&& ((*linkInfoIt)->type
== Antares::Data::atAC /*|| (*linkInfoIt)->type == linkInfo::tyACPST*/))
{
enabledACLines.push_back(*linkInfoIt);
enabledACLines.push_back((*linkInfoIt).get());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
** 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 <https://opensource.org/license/mpl-2-0/>.
*/
* 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 <https://opensource.org/license/mpl-2-0/>.
*/
#ifndef __ANTARES_CONSTRAINTSBUILDER_BUILDER_CBUILDER_H__
#define __ANTARES_CONSTRAINTSBUILDER_BUILDER_CBUILDER_H__

Expand Down Expand Up @@ -231,7 +231,7 @@ class CBuilder final
*/
CBuilder(Antares::Data::Study&);
//! Destructor
~CBuilder();
~CBuilder() = default;
//@}

/*!
Expand Down Expand Up @@ -262,7 +262,7 @@ class CBuilder final
{
auto linkIT = std::find_if(pLink.begin(),
pLink.end(),
[&u, &v](const linkInfo* edgeP) -> bool
[&u, &v](std::shared_ptr<linkInfo> edgeP) -> bool
{
if (edgeP->ptr->from->id == u && edgeP->ptr->with->id == v)
{
Expand All @@ -279,7 +279,7 @@ class CBuilder final
});
if (linkIT != pLink.end())
{
return *linkIT;
return linkIT->get();
}

return nullptr;
Expand All @@ -294,11 +294,11 @@ class CBuilder final
auto a = area.second;
std::for_each(pLink.begin(),
pLink.end(),
[&a, this](linkInfo* edgeP)
[&a, this](std::shared_ptr<linkInfo> edgeP)
{
if (edgeP->ptr->from == a || edgeP->ptr->with == a)
{
this->areaToLinks[a].insert(edgeP);
this->areaToLinks[a].insert(edgeP.get());
}
});
}
Expand All @@ -308,7 +308,7 @@ class CBuilder final
{
if (i < pLink.size())
{
return pLink[i];
return pLink[i].get();
}
return nullptr;
}
Expand Down Expand Up @@ -418,7 +418,7 @@ class CBuilder final
const double& secondMember);

public:
Vector pLink;
std::vector<std::shared_ptr<linkInfo>> pLink;

private:
std::string pPrefix;
Expand Down
49 changes: 24 additions & 25 deletions src/solver/constraints-builder/load.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
** 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 <https://opensource.org/license/mpl-2-0/>.
*/
* 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 <https://opensource.org/license/mpl-2-0/>.
*/
#include <yuni/io/file.h>

#include <antares/inifile/inifile.h>
Expand All @@ -43,19 +43,18 @@ bool CBuilder::completeFromStudy()
{
// for all links of the study
// check if it has been enabled in the INI File
std::shared_ptr<linkInfo> k(
findLinkInfoFromNodeNames(j->second->from->id, j->second->with->id));
auto k = findLinkInfoFromNodeNames(j->second->from->id, j->second->with->id);
if (!k)
{
k = std::make_shared<linkInfo>();
auto infos = std::make_shared<linkInfo>();

logs.info() << "Read data (link " << nCount++ << ")";
// if Yes, complete the linkInfo
// load the pointer
k->ptr = j->second;
k->type = k->ptr->assetType;
infos->ptr = j->second;
infos->type = infos->ptr->assetType;

pLink.push_back(k.get());
pLink.push_back(infos);
}
}
}
Expand Down
Loading