Skip to content

Bug(C++): undefined behavior in vertices_builder.h #846

@Sober7135

Description

@Sober7135

Describe the bug, including details regarding any error messages, version, and platform.

  1. graphar::builder::Vertex provides a default constructor that does not initialize id_. However, GetId() can still be called and may return an uninitialized value, which is undefined behavior.

class Vertex {
public:
Vertex() : empty_(true) {}
/**
* @brief Initialize the vertex with a given id.
*
* @param id The id of the vertex.
*/
explicit Vertex(IdType id) : id_(id), empty_(false) {}
/**
* @brief Get id of the vertex.
*
* @return The id of the vertex.
*/
inline IdType GetId() const noexcept { return id_; }

  1. graphar::builder::Vertex also provides SetId(IdType id), but SetId does not set empty_ to false. This seems inconsistent with the Vertex(IdType id) constructor (which sets empty_ = false) and is likely not the expected behavior.

/**
* @brief Set id of the vertex.
*
* @param id The id of the vertex.
*/
inline void SetId(IdType id) { id_ = id; }

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions