Skip to content

CppCheck: made AnalyzerInformation a local object#7086

Merged
firewave merged 1 commit into
cppcheck-opensource:mainfrom
firewave:cppcheck-aninfo
Dec 20, 2024
Merged

CppCheck: made AnalyzerInformation a local object#7086
firewave merged 1 commit into
cppcheck-opensource:mainfrom
firewave:cppcheck-aninfo

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

@firewave firewave commented Dec 8, 2024

No description provided.

@firewave
Copy link
Copy Markdown
Collaborator Author

firewave commented Dec 8, 2024

Needs #7085 merged first.

@firewave
Copy link
Copy Markdown
Collaborator Author

____________________________ test_addon_rerun[True] ____________________________

tmp_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_addon_rerun_True_0')
builddir = True

    @pytest.mark.parametrize("builddir", (False,True))
    def test_addon_rerun(tmp_path, builddir):
        """Rerun analysis and ensure that misra CTU works; with and without build dir"""
        args = [
            '--addon=misra',
            '--enable=style',
            '--template={id}',
            'whole-program']
        # do not use the injection because the directory needs to survive runs
        if builddir:
            args.append('--cppcheck-build-dir=' + str(tmp_path))
        else:
            args.append('--no-cppcheck-build-dir')
        _, _, stderr = cppcheck(args, cwd=__script_dir)
        assert 'misra-c2012-5.8' in stderr
        _, _, stderr = cppcheck(args, cwd=__script_dir)
>       assert 'misra-c2012-5.8' in stderr
E       assert 'misra-c2012-5.8' in "misra-c2012-8.4\n/home/runner/work/cppcheck/cppcheck/lib/analyzerinfo.cpp:155:23: runtime error: member call on address 0x55f3cb267c20 which does not point to an object of type 'std::basic_ofstream<char>'\n0x55f3cb267c20: note: object has invalid vptr\n 00 00 00 00  67 b2 3c 5f 05 00 00 00  b4 46 27 23 8c 93 17 ed  00 00 00 00 00 00 00 00  00 00 00 00\n              ^~~~~~~~~~~~~~~~~~~~~~~\n              invalid vptr\n    #0 0x55f3c92e880c in AnalyzerInformation::reportErr(ErrorMessage const&) /home/runner/work/cppcheck/cppcheck/lib/analyzerinfo.cpp:155:23\n    #1 0x55f3c957d562 in CppCheck::CppCheckLogger::reportErr(ErrorMessage const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:216:35\n    #2 0x55f3c9574f08 in CppCheck::executeAddons(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:1745:26\n    #3 0x55f3c9576aa9 in CppCheck::executeAddonsWholeProgram(std::__cxx11::list<FileWithDetails, std::allocator<FileWithDetails>> const&, std::__cxx11::list<FileSettings, std::allocator<FileSettings>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:1784:9\n    #4 0x55f3c9579927 in CppCheck::analyseWholeProgram(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::list<FileWithDetails, std::allocator<FileWithDetails>> const&, std::__cxx11::list<FileSettings, std::allocator<FileSettings>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:1983:5\n    #5 0x55f3c90d8462 in CppCheckExecutor::check_internal(Settings const&) const /home/runner/work/cppcheck/cppcheck/cli/cppcheckexecutor.cpp:454:29\n    #6 0x55f3c90d7229 in CppCheckExecutor::check_wrapper(Settings const&) /home/runner/work/cppcheck/cppcheck/cli/cppcheckexecutor.cpp:377:12\n    #7 0x55f3c90d7229 in CppCheckExecutor::check(int, char const* const*) /home/runner/work/cppcheck/cppcheck/cli/cppcheckexecutor.cpp:363:21\n    #8 0x55f3c90c097d in main /home/runner/work/cppcheck/cppcheck/cli/main.cpp:90:21\n    #9 0x7f2c01629d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 490fef840[324](https://github.com/danmar/cppcheck/actions/runs/12339185279/job/34435086975#step:16:325)0c91833978d494d39e537409b92e)\n    #10 0x7f2c01629e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)\n    #11 0x55f3c9093f74 in _start (/home/runner/work/cppcheck/cppcheck/cmake.output/bin/cppcheck+0x2d2f74) (BuildId: 05a35b48557f0df0fc0bb91e9195560b4ef17a72)\n\nSUMMARY: UndefinedBehaviorSanitizer: dynamic-type-mismatch /home/runner/work/cppcheck/cppcheck/lib/analyzerinfo.cpp:155:23 \n"

test/cli/whole-program_test.py:231: AssertionError
/home/runner/work/cppcheck/cppcheck/lib/analyzerinfo.cpp:155:23: runtime error: member call on address 0x55f3cb267c20 which does not point to an object of type 'std::basic_ofstream<char>'
#0 0x55f3c92e880c in AnalyzerInformation::reportErr(ErrorMessage const&) /home/runner/work/cppcheck/cppcheck/lib/analyzerinfo.cpp:155:23
#1 0x55f3c957d562 in CppCheck::CppCheckLogger::reportErr(ErrorMessage const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:216:35
#2 0x55f3c9574f08 in CppCheck::executeAddons(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:1745:26
#3 0x55f3c9576aa9 in CppCheck::executeAddonsWholeProgram(std::__cxx11::list<FileWithDetails, std::allocator<FileWithDetails>> const&, std::__cxx11::list<FileSettings, std::allocator<FileSettings>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:1784:9
#4 0x55f3c9579927 in CppCheck::analyseWholeProgram(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::list<FileWithDetails, std::allocator<FileWithDetails>> const&, std::__cxx11::list<FileSettings, std::allocator<FileSettings>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/runner/work/cppcheck/cppcheck/lib/cppcheck.cpp:1983:5
#5 0x55f3c90d8462 in CppCheckExecutor::check_internal(Settings const&) const /home/runner/work/cppcheck/cppcheck/cli/cppcheckexecutor.cpp:454:29
#6 0x55f3c90d7229 in CppCheckExecutor::check_wrapper(Settings const&) /home/runner/work/cppcheck/cppcheck/cli/cppcheckexecutor.cpp:377:12
#7 0x55f3c90d7229 in CppCheckExecutor::check(int, char const* const*) /home/runner/work/cppcheck/cppcheck/cli/cppcheckexecutor.cpp:363:21
#8 0x55f3c90c097d in main /home/runner/work/cppcheck/cppcheck/cli/main.cpp:90:21
#9 0x7f2c01629d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 490fef840[324](https://github.com/danmar/cppcheck/actions/runs/12339185279/job/34435086975#step:16:325)0c91833978d494d39e537409b92e)
#10 0x7f2c01629e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)
#11 0x55f3c9093f74 in _start (/home/runner/work/cppcheck/cppcheck/cmake.output/bin/cppcheck+0x2d2f74) (BuildId: 05a35b48557f0df0fc0bb91e9195560b4ef17a72)

The AnalyzerInformation pointer in CppCheckLogger was not reset in all cases and now that the object is local we are accessing invalid memory.

Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

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

good! 👍

@firewave firewave merged commit 88d2e31 into cppcheck-opensource:main Dec 20, 2024
@firewave firewave deleted the cppcheck-aninfo branch December 20, 2024 19:25
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 this pull request may close these issues.

2 participants