From 9bae9a439334da23a2a5685f88ca9761c81dbbdf Mon Sep 17 00:00:00 2001 From: Loris Ercole Date: Tue, 16 Jun 2026 09:02:20 +0200 Subject: [PATCH 1/2] Fix MSVC C4996/C4242 warnings in C API - c_status.hpp: replace std::strcpy with std::memcpy using the already computed length. Avoids C4996 (deprecation of strcpy) portably without resorting to _CRT_SECURE_NO_WARNINGS or the non-portable strcpy_s. - c_xc_integrator.cxx: replace ::toupper passed to std::transform with a lambda that takes unsigned char and casts the result back to char. Fixes C4242 (int->char loss-of-data) and avoids UB when char is signed. --- src/c-api/c_status.hpp | 5 +++-- src/c-api/c_xc_integrator.cxx | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/c-api/c_status.hpp b/src/c-api/c_status.hpp index 35292878..6529d551 100644 --- a/src/c-api/c_status.hpp +++ b/src/c-api/c_status.hpp @@ -34,8 +34,9 @@ static inline void gauxc_status_handle(C::GauXCStatus* status, int code, const c if (status->message != nullptr) { std::free(status->message); } - status->message = (char*)std::malloc(std::strlen(message) + 1); - std::strcpy(status->message, message); + const std::size_t len = std::strlen(message) + 1; + status->message = (char*)std::malloc(len); + std::memcpy(status->message, message, len); } else { GAUXC_GENERIC_EXCEPTION(message); } diff --git a/src/c-api/c_xc_integrator.cxx b/src/c-api/c_xc_integrator.cxx index e6832bf5..65768142 100644 --- a/src/c-api/c_xc_integrator.cxx +++ b/src/c-api/c_xc_integrator.cxx @@ -133,7 +133,8 @@ GauXCIntegrator gauxc_integrator_new( // Create Integrator instance auto input_type_ = std::string(integrator_input_type); - std::transform( input_type_.begin(), input_type_.end(), input_type_.begin(), ::toupper ); + std::transform( input_type_.begin(), input_type_.end(), input_type_.begin(), + [](unsigned char c) { return static_cast(std::toupper(c)); } ); if( input_type_ != "REPLICATED" ) GAUXC_GENERIC_EXCEPTION("INTEGRATOR TYPE NOT RECOGNIZED"); From 1e9d122b5c7d98b3d8187cee2ecb804b0b511136 Mon Sep 17 00:00:00 2001 From: Loris Ercole Date: Wed, 24 Jun 2026 10:57:29 +0200 Subject: [PATCH 2/2] Guard split() with EXCHCXX_ENABLE_LIBXC to fix unused-function warning --- src/c-api/c_functional.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/c-api/c_functional.cxx b/src/c-api/c_functional.cxx index d866a6c8..729d41ae 100644 --- a/src/c-api/c_functional.cxx +++ b/src/c-api/c_functional.cxx @@ -19,6 +19,7 @@ #include "c_functional.hpp" #include "c_status.hpp" +#ifdef EXCHCXX_ENABLE_LIBXC namespace GauXC::detail { /** * Splits a string into tokens based on a delimiter @@ -28,7 +29,7 @@ namespace GauXC::detail { * \param [in] str std::string to split * \param [in] delimiters Delimiters on which to split str */ -static inline void split(std::vector& tokens, +static inline void split(std::vector& tokens, const std::string& str, const std::string& delimiters = " ") { tokens.clear(); @@ -47,6 +48,7 @@ static inline void split(std::vector& tokens, } }; // split } // namespace GauXC::detail +#endif namespace GauXC::C { extern "C" {