for循环中的隐式内存别名 [英] Implicit memory aliasing in for loop

查看:231
本文介绍了for循环中的隐式内存别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用golangci-lint,但在以下代码上出现错误:

I'm using golangci-lint and I'm getting an error on the following code:

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文档中找不到任何错误描述.我不明白这个错误.

What does "implicit memory aliasing in for loop" mean, exactly? I could not find any error description in the golangci-lint documentation. I don't understand this error.

推荐答案

索引将解决此问题:

for i := range versions {
    res := createWorkerFor(&versions[i])
    ...

}

这篇关于for循环中的隐式内存别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆