From 46f62aad85c34ff02890cecda1a687729415dd2a Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 25 Aug 2023 09:09:08 -0500 Subject: [PATCH 1/2] During exception handling check if it is not null before using Coverity tool flags use of "it->signature" citing that it could be a nullptr. I suppose the thinking was that exception can only arise within the loop (so `it` is not null per loop termination condition), but perhaps it is better to be safe. --- include/pybind11/pybind11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index db91639dc0..c75e4d2977 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1168,7 +1168,7 @@ class cpp_function : public function { if (!result) { std::string msg = "Unable to convert function return value to a " "Python type! The signature was\n\t"; - msg += it->signature; + msg += (it) ? it->signature : std::string("unavailable"); append_note_if_missing_header_is_suspected(msg); // Attach additional error info to the exception if supported if (PyErr_Occurred()) { From 6ba99e926987c3a26b5100d1436b14de0b01259a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 17:12:19 +0000 Subject: [PATCH 2/2] style: pre-commit fixes --- include/pybind11/pybind11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index c75e4d2977..fa629324a7 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1168,7 +1168,7 @@ class cpp_function : public function { if (!result) { std::string msg = "Unable to convert function return value to a " "Python type! The signature was\n\t"; - msg += (it) ? it->signature : std::string("unavailable"); + msg += (it) ? it->signature : std::string("unavailable"); append_note_if_missing_header_is_suspected(msg); // Attach additional error info to the exception if supported if (PyErr_Occurred()) {