From 12637a2b127143fc59fc479aa86371af2cf489e2 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Wed, 24 Jan 2024 11:26:51 -0800 Subject: [PATCH] Fix shadowed variable in faiss/utils/utils.cpp Summary: Our upcoming compiler upgrade will require us not to have shadowed variables. Such variables have a _high_ bug rate and reduce readability, so we would like to avoid them even if the compiler was not forcing us to do so. This codemod attempts to fix an instance of a shadowed variable. Please review with care: if it's failed the result will be a silent bug. **What's a shadowed variable?** Shadowed variables are variables in an inner scope with the same name as another variable in an outer scope. Having the same name for both variables might be semantically correct, but it can make the code confusing to read! It can also hide subtle bugs. This diff fixes such an issue by renaming the variable. - If you approve of this diff, please use the "Accept & Ship" button :-) Reviewed By: algoriddle Differential Revision: D52959071 fbshipit-source-id: c71b331f9a1ee214cfef8143fdd41c336284d8a2 --- faiss/utils/utils.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/faiss/utils/utils.cpp b/faiss/utils/utils.cpp index c39a1bf5eb..dc6faddaf5 100644 --- a/faiss/utils/utils.cpp +++ b/faiss/utils/utils.cpp @@ -582,9 +582,9 @@ int64_t count_gt(int64_t n, const T* row, T threshold) { } // namespace template -void CombinerRangeKNN::compute_sizes(int64_t* L_res) { - this->L_res = L_res; - L_res[0] = 0; +void CombinerRangeKNN::compute_sizes(int64_t* L_res_2) { + this->L_res = L_res_2; + L_res_2[0] = 0; int64_t j = 0; for (int64_t i = 0; i < nq; i++) { int64_t n_in; @@ -595,11 +595,11 @@ void CombinerRangeKNN::compute_sizes(int64_t* L_res) { n_in = lim_remain[j + 1] - lim_remain[j]; j++; } - L_res[i + 1] = n_in; // L_res[i] + n_in; + L_res_2[i + 1] = n_in; // L_res_2[i] + n_in; } // cumsum for (int64_t i = 0; i < nq; i++) { - L_res[i + 1] += L_res[i]; + L_res_2[i + 1] += L_res_2[i]; } }