Skip to content

Commit

Permalink
Fix shadowed variable in mapillary/opensfm/opensfm/src/third_party/ak…
Browse files Browse the repository at this point in the history
…aze/lib/nldiffusion_functions.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: palmje

Differential Revision: D64398715

fbshipit-source-id: 5a49263b83945d723e9f3046fb13e260e9c6af11
  • Loading branch information
r-barnes authored and facebook-github-bot committed Oct 15, 2024
1 parent 61c0f12 commit 4b19f0d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions opensfm/src/third_party/akaze/lib/nldiffusion_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,22 @@ void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float
Lstep_row = Lstep.ptr<float>(i);

float xpos_2 = (c_row_2[0]+c_row_2[1])*(Ld_row_2[1]-Ld_row_2[0]);
float ypos = (c_row_2[0]+c_row_p_2[0])*(Ld_row_p_2[0]-Ld_row_2[0]);
float ypos_2 = (c_row_2[0]+c_row_p_2[0])*(Ld_row_p_2[0]-Ld_row_2[0]);
float yneg = (c_row_m[0]+c_row_2[0])*(Ld_row_2[0]-Ld_row_m[0]);
Lstep_row[0] = 0.5*stepsize*(xpos_2+ypos-yneg);
Lstep_row[0] = 0.5*stepsize*(xpos_2+ypos_2-yneg);

float xneg = (c_row_2[Lstep.cols-2]+c_row_2[Lstep.cols-1])*(Ld_row_2[Lstep.cols-1]-Ld_row_2[Lstep.cols-2]);
ypos = (c_row_2[Lstep.cols-1]+c_row_p_2[Lstep.cols-1])*(Ld_row_p_2[Lstep.cols-1]-Ld_row_2[Lstep.cols-1]);
float xneg_2 = (c_row_2[Lstep.cols-2]+c_row_2[Lstep.cols-1])*(Ld_row_2[Lstep.cols-1]-Ld_row_2[Lstep.cols-2]);
ypos_2 = (c_row_2[Lstep.cols-1]+c_row_p_2[Lstep.cols-1])*(Ld_row_p_2[Lstep.cols-1]-Ld_row_2[Lstep.cols-1]);
yneg = (c_row_m[Lstep.cols-1]+c_row_2[Lstep.cols-1])*(Ld_row_2[Lstep.cols-1]-Ld_row_m[Lstep.cols-1]);
Lstep_row[Lstep.cols-1] = 0.5*stepsize*(-xneg+ypos-yneg);
Lstep_row[Lstep.cols-1] = 0.5*stepsize*(-xneg_2+ypos_2-yneg);
}

// Ld = Ld + Lstep
for (int y = 0; y < Lstep.rows; y++) {
float* Ld_row = Ld.ptr<float>(y);
float* Lstep_row = Lstep.ptr<float>(y);
for (int x = 0; x < Lstep.cols; x++) {
Ld_row[x] = Ld_row[x] + Lstep_row[x];
float* Ld_row_2 = Ld.ptr<float>(y);
float* Lstep_row_2 = Lstep.ptr<float>(y);
for (int x_2 = 0; x_2 < Lstep.cols; x_2++) {
Ld_row_2[x_2] = Ld_row_2[x_2] + Lstep_row_2[x_2];
}
}
}
Expand Down

0 comments on commit 4b19f0d

Please sign in to comment.