From b23abf440adb6ede034140d0f40962526050f8fc Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 21 Feb 2024 13:50:51 +0100 Subject: [PATCH] src/operators/verify_cc.cc: reduce the scope of variable in a for () loop In general, it is always preferable to reduce the scope of a variable in a for loop --- src/operators/verify_cc.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/operators/verify_cc.cc b/src/operators/verify_cc.cc index ee39902d..8a36bb7e 100644 --- a/src/operators/verify_cc.cc +++ b/src/operators/verify_cc.cc @@ -59,7 +59,6 @@ int VerifyCC::luhnVerify(const char *ccnumber, int len) { int sum[2] = { 0, 0 }; int odd = 0; int digits = 0; - int i; /* Weighted lookup table which is just a precalculated (i = index): * i*2 + (( (i*2) > 9 ) ? -9 : 0) @@ -71,7 +70,7 @@ int VerifyCC::luhnVerify(const char *ccnumber, int len) { /* Add up only digits (weighted digits via lookup table) * for both odd and even CC numbers to avoid 2 passes. */ - for (i = 0; i < len; i++) { + for (int i = 0;i < len;i++) { if (ccnumber[i] >= (0 + 48) && ccnumber[i] <= (9 + 48)) { sum[0] += (!odd ? wtable[ccnumber[i] - '0'] : (ccnumber[i] - '0')); sum[1] += (odd ? wtable[ccnumber[i] - '0'] : (ccnumber[i] - '0'));