jfrog / build-info-go

build-info-go is a Go library and a CLI, which allows generating build-info for a source code project.
https://www.buildinfo.org
Apache License 2.0
64 stars 37 forks source link

Fix implicit memory aliasing in for loop #48

Closed yahavi closed 2 years ago

yahavi commented 2 years ago

Fixes implicit memory aliasing in for loop whereby the targetBuildInfo modules may be reused accidentally:

for i := range targetBuildInfo.Modules {
    if newModule.Id == targetBuildInfo.Modules[i].Id {
        mergeModules(&newModule, &targetBuildInfo.Modules[i]) // This line is troublesome
    }
}

For more info see: https://stackoverflow.com/questions/62446118/implicit-memory-aliasing-in-for-loop/68247837