Skip to content

Commit 28c9a1d

Browse files
SS-JIAfacebook-github-bot
authored andcommitted
Fix underflow error in calculate_dim_order() (#5498)
Summary: Pull Request resolved: #5498 ## Context FIx an underflow error. The issue is that `ndim` is unsigned, therefore if it is `0` when it gets subtracted by one it underflows. Not sure why this wasn't caught by CI tests before. ghstack-source-id: 243610987 exported-using-ghexport Reviewed By: jorgep31415 Differential Revision: D63050011 fbshipit-source-id: d5ea57c00d3b5c4adb577c74d7a10c7840643ae3
1 parent 16673f9 commit 28c9a1d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

backends/vulkan/runtime/api/containers/Tensor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ std::vector<int64_t> calculate_dim_order(
2121
return {0};
2222
}
2323
std::vector<int64_t> dim_order(ndim);
24-
int64_t last_dim = ndim - 1 - packed_dim;
24+
// Explicitly convert ndim to signed to prevent underflow
25+
int64_t last_dim = int64_t(ndim) - 1 - packed_dim;
2526

2627
int64_t cur_dim = 0;
2728
for (int d = 0; d < ndim; ++d) {

0 commit comments

Comments
 (0)