Skip to content

Commit 83c21ea

Browse files
JaRoSchmfbourgey
andauthored
BUG: amos/amos.h: fix scope of l in seri (#92)
* 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. * TST: add test for gh-92 * TST: add test for #92 * revert fix * Update tests/xsf_tests/test_amos.cpp Co-authored-by: Florian Bourgey <bourgeyflorian@gmail.com> * revert 'revert fix' --------- Co-authored-by: Florian Bourgey <bourgeyflorian@gmail.com>
1 parent f5a4b15 commit 83c21ea

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

include/xsf/amos/amos.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,8 +4476,8 @@ namespace amos {
44764476
//
44774477
s1 = w[0];
44784478
s2 = w[1];
4479-
l = 3;
4480-
for (int l = 3; l < (nn + 1); l++) {
4479+
int l;
4480+
for (l = 3; l < (nn + 1); l++) {
44814481
ck = s2;
44824482
s2 = s1 + (ak + fnu) * rz * s2;
44834483
s1 = ck;

tests/xsf_tests/test_amos.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ TEST_CASE("amos besi vectorized", "[amos][xsf_tests]") {
6262
}
6363
}
6464

65+
TEST_CASE("amos seri buffer overflow gh-92", "[amos][xsf_tests]") {
66+
using std::complex;
67+
68+
// parameters for besh which trigger overflow in seri
69+
const complex<double> z{14.0, -3.0};
70+
const double fnu = 1.0;
71+
const int m = 1;
72+
const int n = 260;
73+
const int kode = 1;
74+
75+
const complex<double> sentinel{12345.67, 98765.43};
76+
std::vector<complex<double>> cy(n + 2, sentinel);
77+
78+
int ierr = 0;
79+
int nz = xsf::amos::besh(z, fnu, kode, m, n, cy.data() + 1, &ierr);
80+
81+
// check if guards elements were touched
82+
CAPTURE(cy[0], cy[n + 1]);
83+
CHECK(cy[0] == sentinel);
84+
CHECK(cy[n + 1] == sentinel);
85+
}
86+
6587
TEST_CASE("amos asyi buffer overflow gh-158", "[amos][xsf_tests]") {
6688
using std::complex;
6789

0 commit comments

Comments
 (0)