From 95986ccfaa3d9c8dc0f69423dd917d83b4304f9b Mon Sep 17 00:00:00 2001 From: mhucka Date: Wed, 18 Jun 2025 22:22:14 +0000 Subject: [PATCH 1/2] Replace sprintf() call with snprintf() clang on MacOS complains that sprintf() is insecure and should be replaced with snprintf(). --- pybind_interface/pybind_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybind_interface/pybind_main.cpp b/pybind_interface/pybind_main.cpp index 2520d054f..fe7f30c1e 100644 --- a/pybind_interface/pybind_main.cpp +++ b/pybind_interface/pybind_main.cpp @@ -40,7 +40,7 @@ template T parseOptions(const py::dict &options, const char *key) { if (!options.contains(key)) { char msg[100]; - std::sprintf(msg, "Argument %s is not provided.\n", key); + std::snprintf(msg, sizeof(msg), "Argument %s is not provided.\n", key); throw std::invalid_argument(msg); } const auto &value = options[key]; From 6e8daced2ec1628134536d87e774065f009bb295 Mon Sep 17 00:00:00 2001 From: mhucka Date: Fri, 20 Jun 2025 21:31:03 +0000 Subject: [PATCH 2/2] Use C++ string type Per [review comment by @pavoljuhas](https://github.com/quantumlib/qsim/pull/785#pullrequestreview-2941057906), rewrote the assignment to `msg` to use C++ types. --- pybind_interface/pybind_main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pybind_interface/pybind_main.cpp b/pybind_interface/pybind_main.cpp index fe7f30c1e..80b7da740 100644 --- a/pybind_interface/pybind_main.cpp +++ b/pybind_interface/pybind_main.cpp @@ -39,8 +39,7 @@ namespace { template T parseOptions(const py::dict &options, const char *key) { if (!options.contains(key)) { - char msg[100]; - std::snprintf(msg, sizeof(msg), "Argument %s is not provided.\n", key); + std::string msg = std::string("Argument ") + key + " is not provided.\n"; throw std::invalid_argument(msg); } const auto &value = options[key];