Skip to content

Commit 1be1d32

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in faiss/impl/io.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: meyering Differential Revision: D52582928 fbshipit-source-id: 57bd901e87cbb8ddfd423c8ae6baefe1048c206f
1 parent 7442a54 commit 1be1d32

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

faiss/impl/io.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ size_t BufferedIOWriter::operator()(
196196
while (size > 0) {
197197
assert(b0 == bsz);
198198
// now we need to flush to add more bytes
199-
size_t ofs = 0;
199+
size_t ofs_2 = 0;
200200
do {
201-
assert(ofs < 10000000);
202-
size_t written = (*writer)(buffer.data() + ofs, 1, bsz - ofs);
201+
assert(ofs_2 < 10000000);
202+
size_t written = (*writer)(buffer.data() + ofs_2, 1, bsz - ofs_2);
203203
FAISS_THROW_IF_NOT(written > 0);
204-
ofs += written;
205-
} while (ofs != bsz);
204+
ofs_2 += written;
205+
} while (ofs_2 != bsz);
206206

207207
// copy src to buffer
208208
size_t nb1 = std::min(bsz, size);
@@ -217,12 +217,12 @@ size_t BufferedIOWriter::operator()(
217217
}
218218

219219
BufferedIOWriter::~BufferedIOWriter() {
220-
size_t ofs = 0;
221-
while (ofs != b0) {
222-
// printf("Destructor write %zd \n", b0 - ofs);
223-
size_t written = (*writer)(buffer.data() + ofs, 1, b0 - ofs);
220+
size_t ofs_2 = 0;
221+
while (ofs_2 != b0) {
222+
// printf("Destructor write %zd \n", b0 - ofs_2);
223+
size_t written = (*writer)(buffer.data() + ofs_2, 1, b0 - ofs_2);
224224
FAISS_THROW_IF_NOT(written > 0);
225-
ofs += written;
225+
ofs_2 += written;
226226
}
227227
}
228228

0 commit comments

Comments
 (0)