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 example-chat #743

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

keith-dev
Copy link
Contributor

example-chat has runtime errors because std::function<> is assigned null in places.

This is a fix for that, with unittests.

@mrozigor
Copy link
Member

What is the exact error? As far as I see in the code, these handlers are checked for null before calling them. Maybe problem is with example?

@keith-dev
Copy link
Contributor Author

keith-dev commented Jan 30, 2024

> What is the exact error? As far as I see in the code, these handlers are checked for null before calling them. Maybe problem is with example?

The application crashes, segfaults. I ran it on Android 15 under Termux (clang) and Linux (probably clang again) where it crashed.

Using gdb, the crash is caused by assigning null to a std::function.

The crash can be reproduced on Lunux by compiling with clang and just using example-chat, the faulty code is in Crow, not the example.

The check for null isn't the problem, it's assigning null that's the problem.

@gittiver gittiver added bug Something isn't working discussion The viability / implementation of the issue is up for debate labels Jan 30, 2024
@mrozigor
Copy link
Member

mrozigor commented Feb 2, 2024

Ok, thanks for info. So the only thing is that you can create lambda_wrapper with nullptr.

Comment on lines +929 to +936
ReturnType operator()(Args... args) const
{
if (valid_)
{
return func_(args...);
}
throw call_error();
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand what lambda_wrapper does 🙂 After all, std just throws as well

https://en.cppreference.com/w/cpp/utility/functional/function/operator()

Exceptions
Throws std::bad_function_call if *this does not store a callable function target, i.e. !*this == true.

@gittiver gittiver added task Non code related issue further information required existing information is lacking, or feedback is required and removed task Non code related issue labels Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discussion The viability / implementation of the issue is up for debate further information required existing information is lacking, or feedback is required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants