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

Missing return value in graph.h (Undefined Behavior?) #77

Closed
dnezam opened this issue Nov 16, 2022 · 3 comments · Fixed by #78
Closed

Missing return value in graph.h (Undefined Behavior?) #77

dnezam opened this issue Nov 16, 2022 · 3 comments · Fixed by #78

Comments

@dnezam
Copy link
Contributor

dnezam commented Nov 16, 2022

Hello,

while trying to implement an algorithm using your library, I have come across issues when trying to use std::move on a symmetric graph, namely bad_alloc or stack smashing.

After running the code with sanitizers (address and undefined), I got the following message:
gbbs/graph.h:150:20: runtime error: execution reached the end of a value-returning function without returning a value
It seems that the move assignments in graph.h are missing return *this. This might be undefined behaviour, but I am not sure as I am not too familiar with C++. After adding return *this to the end of symmetric_graph& operator=(symmetric_graph&& other) noexcept , the algorithm ran without crashing.

Let me know if you'd like more details regarding when exactly these issues occurred.

Thanks,
Daniel

@dnezam dnezam changed the title Missing return value in graph.h Missing return value in graph.h (Undefined Behavior?) Nov 16, 2022
@Qwendu
Copy link

Qwendu commented Nov 16, 2022

Falling off the end of a function, if it has a non void return value, is Undefined Behaviour in C++.

This happens in gbbs/graph.h
in methods:
gbbs/graph.h:150 symmetric_graph& operator=(symmetric_graph &&other)
gbbs/graph.h:312 symmetric_ptr_graph& operator=(symmetric_ptr_graph &&other)
gbbs/graph.h:475 asymmetric_graph& operator=(asymmetric_graph &&other)
gbbs/graph.h:587 asymmetric_ptr_graph& operator=(asymmetric_ptr_graph &&other)

These seem to be copy and past mistake from the corresponding move constructors.

Cheers!

@tomtseng
Copy link
Member

Thanks for the bug report, does adding a return *this; to the end of each of those functions fix it? I just merged a pull request #78 adding those return statements

@dnezam
Copy link
Contributor Author

dnezam commented Nov 16, 2022

Thanks for the quick response! I added return *this; to the function that I used, and now it works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants