Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

scan-build reports false-positive with boost signals #51511

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR52544
Status NEW
Importance P enhancement
Reported by Florian Apolloner (florian@apolloner.eu)
Reported on 2021-11-18 03:48:05 -0800
Last modified on 2021-11-18 03:58:31 -0800
Version 13.0
Hardware PC Linux
CC dcoughlin@apple.com, florian@apolloner.eu, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments report-496700.html (378600 bytes, text/html)
Blocks
Blocked by
See also

Created attachment 25457 HTML output of scan-build

Hi there,

I have scan-build reporting a false positive. I am not 100% sure though, since this code is a bit over my head and my analysis might have been wrong.

What I did so far:

Looking through the report I think it might indeed be a bug in scan-build (although it might not be easily fixable and might have to be reported to boost signals2/smart_ptr instead).

I have attached the generated html output, the cpp in question is:

#include <boost/signals2.hpp>
#include <boost/bind/bind.hpp>
#include <iostream>

using namespace boost;
using namespace boost::signals2;
using namespace std;

signal<void ()> SigA;

struct ClassB
{
    void PrintFoo() { cout << "Foo" << endl; }
};

int main()
{
    ClassB b;
    SigA.connect(bind(&ClassB::PrintFoo, &b));
}

and scan-build reports:

scan-build: Using '/usr/bin/clang-13' for static analysis
In file included from test.cpp:1:
In file included from /usr/include/boost/signals2.hpp:15:
In file included from /usr/include/boost/signals2/deconstruct.hpp:28:
In file included from /usr/include/boost/shared_ptr.hpp:17:
In file included from /usr/include/boost/smart_ptr/shared_ptr.hpp:17:
/usr/include/boost/smart_ptr/detail/shared_count.hpp:586:22: warning: Use of memory after it is freed [cplusplus.NewDelete]
        if(pi_ != 0) pi_->weak_release();
                     ^~~~~~~~~~~~~~~~~~~
1 warning generated.
scan-build: Analysis run complete.
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-2021-11-18-124707-36387-1' to examine bug reports.

Please let me know what you need and whether I should report this to boost instead.

Quuxplusone commented 3 years ago

Attached report-496700.html (378600 bytes, text/html): HTML output of scan-build