From e09e02527e403268516226e6a72385747fe02ad2 Mon Sep 17 00:00:00 2001 From: Susi Lehtola Date: Fri, 6 Feb 2026 10:15:43 +0200 Subject: [PATCH 1/3] Add sanity check for number of primitives --- include/gauxc/shell.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/gauxc/shell.hpp b/include/gauxc/shell.hpp index 7f27170c3..d47864785 100644 --- a/include/gauxc/shell.hpp +++ b/include/gauxc/shell.hpp @@ -138,6 +138,9 @@ class alignas(256) Shell { alpha_( alpha ), coeff_( coeff ), O_( O ), nprim_( nprim.get() ), l_( l.get() ), pure_( pure.get() ) { + if(nprim_ > detail::shell_nprim_max) + throw std::out_of_range("Shell has too many primitives!\n"); + if( _normalize ) normalize(); compute_shell_cutoff(); From 4c28c8b06f0b928cd992de5d78611975a592bfb0 Mon Sep 17 00:00:00 2001 From: Susi Lehtola Date: Fri, 6 Feb 2026 17:55:22 +0200 Subject: [PATCH 2/3] Revision based on code review: include expected and erroneous values. --- include/gauxc/shell.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/gauxc/shell.hpp b/include/gauxc/shell.hpp index d47864785..01d35f429 100644 --- a/include/gauxc/shell.hpp +++ b/include/gauxc/shell.hpp @@ -138,8 +138,11 @@ class alignas(256) Shell { alpha_( alpha ), coeff_( coeff ), O_( O ), nprim_( nprim.get() ), l_( l.get() ), pure_( pure.get() ) { - if(nprim_ > detail::shell_nprim_max) - throw std::out_of_range("Shell has too many primitives!\n"); + if(nprim_ > detail::shell_nprim_max) { + std::ostringstream oss; + oss << "Shell has too many primitives! expected <= " << detail::shell_nprim_max << " actual value " << nprim_ << "!\n"; + throw std::out_of_range(oss.str()); + } if( _normalize ) normalize(); compute_shell_cutoff(); From c28504d87a6999c7c85c596516103a85ebefc262 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert Date: Mon, 27 Apr 2026 08:58:48 +0200 Subject: [PATCH 3/3] Add test case and fix imports --- include/gauxc/shell.hpp | 4 +++- tests/basisset_test.cxx | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/gauxc/shell.hpp b/include/gauxc/shell.hpp index 01d35f429..32cb50e65 100644 --- a/include/gauxc/shell.hpp +++ b/include/gauxc/shell.hpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -138,7 +140,7 @@ class alignas(256) Shell { alpha_( alpha ), coeff_( coeff ), O_( O ), nprim_( nprim.get() ), l_( l.get() ), pure_( pure.get() ) { - if(nprim_ > detail::shell_nprim_max) { + if(nprim_ > static_cast(detail::shell_nprim_max)) { std::ostringstream oss; oss << "Shell has too many primitives! expected <= " << detail::shell_nprim_max << " actual value " << nprim_ << "!\n"; throw std::out_of_range(oss.str()); diff --git a/tests/basisset_test.cxx b/tests/basisset_test.cxx index 295653369..51fa39556 100644 --- a/tests/basisset_test.cxx +++ b/tests/basisset_test.cxx @@ -20,6 +20,8 @@ #include #include +#include +#include #include @@ -184,6 +186,25 @@ TEST_CASE("Shell", "[basisset]") { } + SECTION("Too Many Primitives") { + + const auto nprim = PrimSize(detail::shell_nprim_max + 1); + const prim_array alpha = {0.8}; + const prim_array coeff = {0.5}; + + try { + Shell sh( nprim, AngularMomentum(0), SphericalType(false), + alpha, coeff, center ); + FAIL( "Expected Shell construction to throw" ); + } catch( const std::out_of_range& ex ) { + const std::string message = ex.what(); + CHECK( message.find( "Shell has too many primitives!" ) != std::string::npos ); + CHECK( message.find( "expected <= 32" ) != std::string::npos ); + CHECK( message.find( "actual value 33" ) != std::string::npos ); + } + + } + }