Copilot commented on code in PR #13132:
URL: https://github.com/apache/trafficserver/pull/13132#discussion_r3170117059


##########
src/iocore/hostdb/HostDB.cc:
##########
@@ -1610,7 +1609,7 @@ HostDBRecord::select_best_srv(char *target, InkRand 
*rand, ts_time now, ts_secon
   HostDBInfo *live[rr.count()];
   for (auto &target : rr) {
     // skip down targets.
-    if (rr[i].is_down(now, fail_window)) {
+    if (target.is_down(now, fail_window)) {

Review Comment:
   The range-for loop variable `target` shadows the output parameter `char 
*target`, which makes the function harder to read and easier to accidentally 
misuse. Consider renaming the loop variable (e.g., `rr_target`/`srv_target`) or 
the output buffer parameter to avoid shadowing.



##########
src/iocore/hostdb/HostDB.cc:
##########
@@ -1627,6 +1626,7 @@ HostDBRecord::select_best_srv(char *target, InkRand 
*rand, ts_time now, ts_secon
     result = this->select_next_rr(now, fail_window);
   } else {
     uint32_t xx = rand->random() % weight;
+    int      i  = 0;
     for (i = 0; i < live_n - 1 && xx >= live[i]->data.srv.srv_weight; ++i) {

Review Comment:
   `i` is initialized to 0 at declaration and then immediately re-initialized 
in the `for` initializer. Consider removing the redundant `i = 0` in the loop 
header (use `for (; ... )`) to avoid duplication.
   ```suggestion
       for (; i < live_n - 1 && xx >= live[i]->data.srv.srv_weight; ++i) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to