Skip to content

Commit 2ffcf12

Browse files
authored
Merge pull request #75 from keichi/fix-int-overflow-indices
Use size_t for View indices to prevent potential integer overflow
2 parents 3a221e3 + e6135d1 commit 2ffcf12

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/io.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Dataset load_csv(const std::string &path)
2121
throw std::invalid_argument("Failed to open file " + path);
2222
}
2323

24-
auto n_rows = 0;
25-
auto n_columns = 0;
26-
auto is_header = true;
24+
size_t n_rows = 0;
25+
size_t n_columns = 0;
26+
bool is_header = true;
2727

2828
while (ifs >> line) {
2929
std::stringstream ss(line);
@@ -51,8 +51,8 @@ Dataset load_csv(const std::string &path)
5151
auto ds = MutableDataset("dataset", n_rows, n_columns);
5252
auto mirror = Kokkos::create_mirror_view(ds);
5353

54-
for (auto i = 0; i < n_columns; i++) {
55-
for (auto j = 0; j < n_rows; j++) {
54+
for (size_t i = 0; i < n_columns; i++) {
55+
for (size_t j = 0; j < n_rows; j++) {
5656
mirror(j, i) = columns[i][j];
5757
}
5858
}

src/stats.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ void corrcoef(CrossMap rho, Dataset ds, TimeSeries x)
2323
"EDM::stats::corrcoef",
2424
Kokkos::TeamPolicy<>(ds.extent(1), Kokkos::AUTO),
2525
KOKKOS_LAMBDA(const Kokkos::TeamPolicy<>::member_type &member) {
26-
const int j = member.league_rank();
26+
const size_t j = member.league_rank();
2727
CorrcoefSimpleState state;
2828

2929
Kokkos::parallel_reduce(
3030
Kokkos::TeamThreadRange(member,
3131
Kokkos::min(x.extent(0), ds.extent(0))),
32-
[=](int i, CorrcoefSimpleState &upd) {
32+
[=](size_t i, CorrcoefSimpleState &upd) {
3333
upd += CorrcoefSimpleState(x(i), ds(i, j));
3434
},
3535
Kokkos::Sum<CorrcoefSimpleState>(state));

0 commit comments

Comments
 (0)