Skip to content

Commit

Permalink
Fix shadowed variable in faiss/impl/io.cpp
Browse files Browse the repository at this point in the history
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
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 14, 2024
1 parent 7442a54 commit 1be1d32
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions faiss/impl/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ size_t BufferedIOWriter::operator()(
while (size > 0) {
assert(b0 == bsz);
// now we need to flush to add more bytes
size_t ofs = 0;
size_t ofs_2 = 0;
do {
assert(ofs < 10000000);
size_t written = (*writer)(buffer.data() + ofs, 1, bsz - ofs);
assert(ofs_2 < 10000000);
size_t written = (*writer)(buffer.data() + ofs_2, 1, bsz - ofs_2);
FAISS_THROW_IF_NOT(written > 0);
ofs += written;
} while (ofs != bsz);
ofs_2 += written;
} while (ofs_2 != bsz);

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

BufferedIOWriter::~BufferedIOWriter() {
size_t ofs = 0;
while (ofs != b0) {
// printf("Destructor write %zd \n", b0 - ofs);
size_t written = (*writer)(buffer.data() + ofs, 1, b0 - ofs);
size_t ofs_2 = 0;
while (ofs_2 != b0) {
// printf("Destructor write %zd \n", b0 - ofs_2);
size_t written = (*writer)(buffer.data() + ofs_2, 1, b0 - ofs_2);
FAISS_THROW_IF_NOT(written > 0);
ofs += written;
ofs_2 += written;
}
}

Expand Down

0 comments on commit 1be1d32

Please sign in to comment.