From e6c80f247fe848bfb77dc934526ebf4bc56377de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6seritz-Schmidt?= Date: Tue, 3 Feb 2026 08:37:03 +0100 Subject: [PATCH 1/6] BUG: amos/amos.h: fix scope of l in seri Fix the scope of l such that its value from the loop is conserved after the goto statement in the loop's body. --- include/xsf/amos/amos.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/xsf/amos/amos.h b/include/xsf/amos/amos.h index 87f757a2fc..529c99ef72 100644 --- a/include/xsf/amos/amos.h +++ b/include/xsf/amos/amos.h @@ -4481,8 +4481,8 @@ namespace amos { // s1 = w[0]; s2 = w[1]; - l = 3; - for (int l = 3; l < (nn + 1); l++) { + int l; + for (l = 3; l < (nn + 1); l++) { ck = s2; s2 = s1 + (ak + fnu) * rz * s2; s1 = ck; From 1beee0b81842f31d6ef6dade6cae6bd562b70fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6seritz-Schmidt?= Date: Mon, 11 May 2026 13:44:31 +0200 Subject: [PATCH 2/6] TST: add test for gh-92 --- tests/xsf_tests/test_amos.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/xsf_tests/test_amos.cpp b/tests/xsf_tests/test_amos.cpp index 620ec6cee3..ae75a73015 100644 --- a/tests/xsf_tests/test_amos.cpp +++ b/tests/xsf_tests/test_amos.cpp @@ -49,3 +49,33 @@ TEST_CASE("amos besj", "[amos][xsf_tests]") { REQUIRE(rel_error <= 1e-14); } } + +TEST_CASE("amos besh vectorized", "[amos][xsf_tests]") { + // tests the functionality of amos to return multiple consecutive orders for besh + // by comparing to the versions returning only a single order + using std::complex; + + using test_case = std::tuple, double, int, int, int, double>; + auto [z, fnu, kode, m, n, rtol] = GENERATE( + test_case{complex{14.0, -3.0}, 1.0, 1, 1, 260, 4e-13} // gh-92 + ); + + std::vector> cy(n); + int ierr = 0; + int nz; + + nz = xsf::amos::besh(z, fnu, kode, m, n, cy.data(), &ierr); + + REQUIRE(ierr == 0); + + complex ref; + + for (int i = 0; i < n; ++i) { + nz = xsf::amos::besh(z, fnu + i, kode, m, 1, &ref, &ierr); + REQUIRE(ierr == 0); + + const auto rel_error = xsf::extended_relative_error(cy[i], ref); + CAPTURE(i, cy[i], ref, rel_error); + REQUIRE(rel_error <= rtol); + } +} From ba780bdedb4d1f2b2e3567261753f39877a7f827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6seritz-Schmidt?= Date: Mon, 8 Jun 2026 08:20:15 +0200 Subject: [PATCH 3/6] TST: add test for https://github.com/scipy/xsf/pull/92 --- tests/xsf_tests/test_amos.cpp | 38 ++++++++++++++--------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/tests/xsf_tests/test_amos.cpp b/tests/xsf_tests/test_amos.cpp index 3eea2da506..c71db8e5eb 100644 --- a/tests/xsf_tests/test_amos.cpp +++ b/tests/xsf_tests/test_amos.cpp @@ -62,34 +62,26 @@ TEST_CASE("amos besi vectorized", "[amos][xsf_tests]") { } } -TEST_CASE("amos besh vectorized", "[amos][xsf_tests]") { - // tests the functionality of amos to return multiple consecutive orders for besh - // by comparing to the versions returning only a single order +TEST_CASE("amos seri buffer overflow gh-92", "[amos][xsf_tests]") { using std::complex; - using test_case = std::tuple, double, int, int, int, double>; - auto [z, fnu, kode, m, n, rtol] = GENERATE( - test_case{complex{14.0, -3.0}, 1.0, 1, 1, 260, 4e-13} // gh-92 - ); - - std::vector> cy(n); - int ierr = 0; - int nz; - - nz = xsf::amos::besh(z, fnu, kode, m, n, cy.data(), &ierr); - - REQUIRE(ierr == 0); + // parameters for besh which trigger overflow in seri + const complex z{14.0, -3.0}; + const double fnu = 1.0; + const int m = 1; + const int n = 260; + const int kode = 1; - complex ref; + // allocate n+1 elements, initialize extra to sentinel to detect overflow + const complex sentinel{12345.67, 98765.43}; + std::vector> cy(n + 1, sentinel); - for (int i = 0; i < n; ++i) { - nz = xsf::amos::besh(z, fnu + i, kode, m, 1, &ref, &ierr); - REQUIRE(ierr == 0); + int ierr = 0; + int nz = xsf::amos::besh(z, fnu, kode, m, n, cy.data(), &ierr); - const auto rel_error = xsf::extended_relative_error(cy[i], ref); - CAPTURE(i, cy[i], ref, rel_error); - REQUIRE(rel_error <= rtol); - } + // check if the extra element (index n) was touched + CAPTURE(cy[n]); + CHECK(cy[n] == sentinel); } TEST_CASE("amos asyi buffer overflow gh-158", "[amos][xsf_tests]") { From a973ddd6c3a043bc526bea2a581346e04d21d976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6seritz-Schmidt?= Date: Mon, 8 Jun 2026 21:21:10 +0200 Subject: [PATCH 4/6] revert fix --- include/xsf/amos/amos.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/xsf/amos/amos.h b/include/xsf/amos/amos.h index 47ead427ce..df6a01a931 100644 --- a/include/xsf/amos/amos.h +++ b/include/xsf/amos/amos.h @@ -4476,8 +4476,10 @@ namespace amos { // s1 = w[0]; s2 = w[1]; - int l; - for (l = 3; l < (nn + 1); l++) { + // int l; + // for (l = 3; l < (nn + 1); l++) { + l = 3; + for (int l = 3; l < (nn + 1); l++) { ck = s2; s2 = s1 + (ak + fnu) * rz * s2; s1 = ck; From 8a3cb53b1425a2de1d73dd67fe959bc6513ec017 Mon Sep 17 00:00:00 2001 From: JaRoSchm Date: Tue, 9 Jun 2026 12:44:11 +0200 Subject: [PATCH 5/6] Update tests/xsf_tests/test_amos.cpp Co-authored-by: Florian Bourgey --- tests/xsf_tests/test_amos.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/xsf_tests/test_amos.cpp b/tests/xsf_tests/test_amos.cpp index c71db8e5eb..0bd0e6706c 100644 --- a/tests/xsf_tests/test_amos.cpp +++ b/tests/xsf_tests/test_amos.cpp @@ -72,16 +72,16 @@ TEST_CASE("amos seri buffer overflow gh-92", "[amos][xsf_tests]") { const int n = 260; const int kode = 1; - // allocate n+1 elements, initialize extra to sentinel to detect overflow const complex sentinel{12345.67, 98765.43}; - std::vector> cy(n + 1, sentinel); + std::vector> cy(n + 2, sentinel); int ierr = 0; - int nz = xsf::amos::besh(z, fnu, kode, m, n, cy.data(), &ierr); + int nz = xsf::amos::besh(z, fnu, kode, m, n, cy.data() + 1, &ierr); - // check if the extra element (index n) was touched - CAPTURE(cy[n]); - CHECK(cy[n] == sentinel); + // check if guards elements were touched + CAPTURE(cy[0], cy[n + 1]); + CHECK(cy[0] == sentinel); + CHECK(cy[n + 1] == sentinel); } TEST_CASE("amos asyi buffer overflow gh-158", "[amos][xsf_tests]") { From 9f9fac1ed409ccf0c6ce8954f04e48fa70c45274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6seritz-Schmidt?= Date: Tue, 9 Jun 2026 12:56:15 +0200 Subject: [PATCH 6/6] revert 'revert fix' --- include/xsf/amos/amos.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/xsf/amos/amos.h b/include/xsf/amos/amos.h index df6a01a931..47ead427ce 100644 --- a/include/xsf/amos/amos.h +++ b/include/xsf/amos/amos.h @@ -4476,10 +4476,8 @@ namespace amos { // s1 = w[0]; s2 = w[1]; - // int l; - // for (l = 3; l < (nn + 1); l++) { - l = 3; - for (int l = 3; l < (nn + 1); l++) { + int l; + for (l = 3; l < (nn + 1); l++) { ck = s2; s2 = s1 + (ak + fnu) * rz * s2; s1 = ck;