Skip to content

[BUG]: Attempt to resize() an object in a std::optional variable that has not been initialized #5155

@mcordery

Description

@mcordery

Version

25.02

Which installation method(s) does this occur on?

No response

Describe the bug.

Note this is the same in 25.08.
In the file cpp/tests/sampling/detail/sampling_post_processing_validate.cu, There is a a resize() operation a line 1350:

(*this_type_unique_minor_hops)
            .resize(this_type_unique_minors.size(), handle.get_stream());

The problem here is that when running the test SAMPLING_HETEROGENEOUS_POST_PROCESSING_TEST, the first pass through the loop the std::optional object this_type_unique_minor hops is initialized to std::nullopt (as is this_type_unique_major_hops). When this happens, the attemped resize of the underlying device_uvector seg faults because of the lack of an previously allocated device_uvector. The fix is something like

          if (this_type_unique_minor_hops) {
            .resize(this_type_unique_minors.size(), handle.get_stream());
            (*this_type_unique_minor_hops)
              .resize(this_type_unique_minors.size(), handle.get_stream());
          }

But probably better to be explicit

          if ((*this_type_unique_minor_hops).has_value()) {
            .resize(this_type_unique_minors.size(), handle.get_stream());
            (*this_type_unique_minor_hops)
              .resize(this_type_unique_minors.size(), handle.get_stream());
          }

Minimum reproducible example

Relevant log output

Environment details

Other/Misc.

No response

Code of Conduct

  • I agree to follow cuGraph's Code of Conduct
  • I have searched the open bugs and have found no duplicates for this bug report

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions