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 unsafe initialization in the Graph class #606

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

caguero
Copy link
Contributor

@caguero caguero commented Jul 2, 2024

🦟 Bug fix

Partially fixes #269 (Graph class).

Summary

I implemented the "Construct on first use" idiom (https://www.freecodecamp.org/news/cpp-static-initialization-order-fiasco/) to avoid the potential unsafe construction.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.98%. Comparing base (c32e96e) to head (05b847d).
Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #606   +/-   ##
=======================================
  Coverage   95.97%   95.98%           
=======================================
  Files         147      147           
  Lines       10122    10130    +8     
=======================================
+ Hits         9715     9723    +8     
  Misses        407      407           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -150,7 +150,7 @@ namespace graph
{
std::cerr << "[Graph::AddVertex()] The limit of vertices has been "
<< "reached. Ignoring vertex." << std::endl;
return Vertex<V>::NullVertex;
return NullVertex<V>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like an API change; we may need to do it, but let me check if sdformat will be affected

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should update the migration guide to document the API break / deprecation, depending on which route we take

@@ -150,7 +150,7 @@ namespace graph
{
std::cerr << "[Graph::AddVertex()] The limit of vertices has been "
<< "reached. Ignoring vertex." << std::endl;
return Vertex<V>::NullVertex;
return NullVertex<V>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -204,9 +205,6 @@ namespace graph
template<typename E>
class UndirectedEdge : public Edge<E>
{
/// \brief An invalid undirected edge.
public: static UndirectedEdge<E> NullEdge;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may choose to make a hard API break here, but I'd prefer to not remove these static types in this pull request, but to deprecate them instead, so that we can coordinate fixes for sdformat and any other gz-* packages in separate pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

None yet

3 participants