Copilot commented on code in PR #734:
URL: https://github.com/apache/dubbo-go-pixiu/pull/734#discussion_r2272954477


##########
pkg/cluster/loadbalancer/rand/load_balancer_rand.go:
##########
@@ -33,5 +33,5 @@ func init() {
 type Rand struct{}
 
 func (Rand) Handler(c *model.ClusterConfig, _ model.LbPolicy) *model.Endpoint {
-       return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints)-1)]
+       return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints)-1)] // NOSONAR

Review Comment:
   This code has a potential index out of bounds issue. When len(c.Endpoints) 
is 1, rand.Intn(0) will panic. The expression should be 
rand.Intn(len(c.Endpoints)) instead of rand.Intn(len(c.Endpoints)-1).
   ```suggestion
        return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints))] // NOSONAR
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to