mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-15 23:01:33 +00:00
fix: remove pointer to loop variable when searching the latest event to analyze (#328)
Having a pointer to a range variable will always yield the latest value the loop sees. This leads to subtle bugs. To prevent this from happening, the range variable was assigned to a temp variable, which is then referenced as a pointer. Signed-off-by: Patrick Pichler <git@patrickpichler.dev> Co-authored-by: Patrick Pichler <git@patrickpichler.dev>
This commit is contained in:
@@ -76,7 +76,11 @@ var ServeCmd = &cobra.Command{
|
||||
if aiProvider == nil {
|
||||
for _, provider := range configAI.Providers {
|
||||
if backend == provider.Name {
|
||||
aiProvider = &provider
|
||||
// he pointer to the range variable is not really an issue here, as there
|
||||
// is a break right after, but to prevent potential future issues, a temp
|
||||
// variable is assigned
|
||||
p := provider
|
||||
aiProvider = &p
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user