我正在使用golangci-lint,并且在以下代码中遇到错误:
versions []ObjectDescription
... (populate versions) ...
for i, v := range versions {
res := createWorkerFor(&v)
...
}
错误是:
G601: Implicit memory aliasing in for loop. (gosec)
res := createWorkerFor(&v)
^
确切地说,“for循环中的隐式内存别名”是什么意思?我在golangci-lint文档中找不到任何错误描述。我不明白这个错误。
最佳答案
索引将解决问题:
for i := range versions {
res := createWorkerFor(&versions[i])
...
}
关于go - for循环中的隐式内存别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62446118/