diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 4f3346a3dc12..80f4019fa769 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -393,7 +393,9 @@ static std::vector executeAddon(const AddonInfo &addonInfo, if (result.size() > 2) { details += "\nOutput:\n"; details += result; - details.resize(details.find_last_not_of("\n\r")); + const auto pos = details.find_last_not_of("\n\r"); + if (pos != std::string::npos) + details.resize(pos + 1); } throw InternalError(nullptr, message, details); } diff --git a/test/cli/test-other.py b/test/cli/test-other.py index d788b9e19be9..7dc5a2992026 100644 --- a/test/cli/test-other.py +++ b/test/cli/test-other.py @@ -413,10 +413,7 @@ def test_invalid_addon_py_verbose(tmpdir): Exceptio [internalError] """ # /tmp/pytest-of-user/pytest-10/test_invalid_addon_py_20/file.cpp:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon1' - exitcode is 256.: python3 /home/user/CLionProjects/cppcheck/addons/runaddon.py /tmp/pytest-of-user/pytest-10/test_invalid_addon_py_20/addon1.py --cli /tmp/pytest-of-user/pytest-10/test_invalid_addon_py_20/file.cpp.24637.dump - # "C:\\Users\\Quotenjugendlicher\\AppData\\Local\\Temp\\pytest-of-Quotenjugendlicher\\pytest-15\\test_execute_addon_failure_20\\test.cpp:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon (command: 'python5.x S:\\GitHub\\cppcheck-fw\\bin\\debug\\addons\\runaddon.py S:\\GitHub\\cppcheck-fw\\bin\\debug\\addons\\naming.py --cli C:\\Users\\Quotenjugendlicher\\AppData\\Local\\Temp\\pytest-of-Quotenjugendlicher\\pytest-15\\test_execute_addon_failure_20\\test.cpp.9892.dump'). Exitcode is nonzero. [internalError]\n\n^\n - print(stderr) assert stderr.startswith("{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon1' - exitcode is 1: ".format(test_file)) - # TODO: string is cut off assert stderr.count('Output:\nTraceback') assert stderr.endswith('raise Exception()\nExceptio [internalError]\n\n^\n')