From 4b19f0d8620f03d0f2e8a82c89dbc46195264b2d Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Tue, 15 Oct 2024 13:59:21 -0700 Subject: [PATCH] Fix shadowed variable in mapillary/opensfm/opensfm/src/third_party/akaze/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 --- .../akaze/lib/nldiffusion_functions.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/opensfm/src/third_party/akaze/lib/nldiffusion_functions.cpp b/opensfm/src/third_party/akaze/lib/nldiffusion_functions.cpp index 9f50abd5a..5fa764094 100644 --- a/opensfm/src/third_party/akaze/lib/nldiffusion_functions.cpp +++ b/opensfm/src/third_party/akaze/lib/nldiffusion_functions.cpp @@ -299,22 +299,22 @@ void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float Lstep_row = Lstep.ptr(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(y); - float* Lstep_row = Lstep.ptr(y); - for (int x = 0; x < Lstep.cols; x++) { - Ld_row[x] = Ld_row[x] + Lstep_row[x]; + float* Ld_row_2 = Ld.ptr(y); + float* Lstep_row_2 = Lstep.ptr(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]; } } }