We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
@Naios
Function2 tags 4.2.0 and 4.2.1, hashes: 02ca998 f569a63
Test case pasted below compiles without errors with g++-11 -O1 -Wnull-dereference -c -o null-deref.o null-deref.cpp
g++-11 -O1 -Wnull-dereference -c -o null-deref.o null-deref.cpp
Test case given below produces a warning for a null pointer dereference:
g++-11 -O1 -Wnull-dereference -c -o null-deref.o null-deref.cpp null-deref.cpp: In static member function ‘static Ret fu2::abi_400::detail::type_erasure::invocation_table::function_trait<Ret(Args ...)>::internal_invoker<T, IsInplace>::invoke(fu2::abi_400::detail::type_erasure::data_accessor*, std::size_t, Args ...) [with T = fu2::abi_400::detail::type_erasure::box<false, Foo::bar()::<lambda()>, std::allocator<Foo::bar()::<lambda()> > >; bool IsInplace = true; Ret = int; Args = {}]’: null-deref.cpp:14:44: warning: potential null pointer dereference [-Wnull-dereference] 14 | CallbackT c = std::move([=]() { return x; }); | ^ null-deref.cpp:14:44: warning: potential null pointer dereference [-Wnull-dereference]
Test case file:
//#include "function2.hpp" #include "function2-upstream-master.hpp" #include <functional> #include <iostream> //#include "function2.hpp-fixed" using namespace std; class Foo { public: using CallbackT = fu2::unique_function<int(void)>; void bar(void) { int x = 10; CallbackT c = std::move([=]() { return x; }); } }; int main(void) { Foo a; a.bar(); return 0; }
Compile with the command:
This issue can be solved by the following patch to function2.hpp
function2.hpp
Patch to tag 4.2.0 --- function2.hpp 2022-06-16 19:56:34.645027778 +0000 +++ function2.hpp-fixed 2022-06-16 15:54:34.989443571 +0000 @@ -573,6 +573,7 @@ auto obj = retrieve<T>(std::integral_constant<bool, IsInplace>{}, \ data, capacity); \ auto box = static_cast<T CONST VOLATILE*>(obj); \ + if(box == nullptr) throw_or_abort##NOEXCEPT(std::integral_constant<bool, false>{}); \ return invocation::invoke( \ static_cast<std::decay_t<decltype(box->value_)> CONST VOLATILE \ REF>(box->value_), \
The text was updated successfully, but these errors were encountered:
Thank you for your report. I'm quite certain that this is a false positive. I will take a closer look into it.
Sorry, something went wrong.
No branches or pull requests
@Naios
Commit Hash
Function2 tags 4.2.0 and 4.2.1, hashes:
02ca998
f569a63
Expected Behavior
Test case pasted below compiles without errors with
g++-11 -O1 -Wnull-dereference -c -o null-deref.o null-deref.cpp
Actual Behavior
Test case given below produces a warning for a null pointer dereference:
Steps to Reproduce
Test case file:
Compile with the command:
This issue can be solved by the following patch to
function2.hpp
Your Environment
The text was updated successfully, but these errors were encountered: