github-vet / github-vet/rangeloop-pointer-findings
zmarvel/photomine: photomine.go; 75 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [zmarvel/photomine](https://www.github.com/zmarvel/photomine) at [photomine.go](https://github.com/zmarvel/photomine/blob/a149cb41b9ec8995037d7fd7a07849ff5d55f586/photomine.go#L191-L265)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable album used in defer or goroutine at line 234
[Click here to see the code in its original context.](https://github.com/zmarvel/photomine/blob/a149cb41b9ec8995037d7fd7a07849ff5d55f586/photomine.go#L191-L265)
Click here to show the 75 line(s) of Go which triggered the analyzer.
```go
for _, album := range index.Albums {
// log.Printf("Album path %s", album.Path)
albumOutputPath := path.Join(outputPath, album.Path)
// Copy the images into the output directory
// TODO maybe allow filtering by filename
inputDir := path.Join(albumsPath, album.Path)
if err = copyDir(inputDir, albumOutputPath); err != nil {
log.Fatalf("Failed to copy images: %v", err)
}
albumDir, err := os.Open(albumOutputPath)
if err != nil {
log.Fatalf("Failed to open album dir %s: %v", albumOutputPath, err)
}
defer albumDir.Close()
photoPaths, err := albumDir.Readdirnames(0)
if err != nil {
log.Fatalf("Failed to read album dir %s: %v", albumOutputPath, err)
}
// Create thumbnails directory
thumbDir := "thumb"
err = os.Mkdir(path.Join(albumOutputPath, thumbDir), 0755)
for _, photoPath := range photoPaths {
if config.hasValidExt(photoPath) {
thumbPath := path.Join(thumbDir, photoPath)
var photo photo
photo.Description = photoPath
photo.Path = photoPath
photo.Thumbnail = thumbPath
parts := strings.Split(photo.Path, ".")
photo.Page = strings.Join(parts[0:len(parts)-1], ".") + ".html"
album.Photos = append(album.Photos, photo)
}
}
sort.Slice(album.Photos, func(i, j int) bool {
return album.Photos[i].Path < album.Photos[j].Path
})
thumbWaitGroup.Add(1)
go func() {
defer thumbWaitGroup.Done()
album.createThumbs(albumOutputPath, thumbDims)
}()
// Build links between photos for next/previous links, and render photo page
for i, photo := range album.Photos {
if i > 0 {
photo.Prev = album.Photos[i-1].Page
}
if i < len(album.Photos)-1 {
photo.Next = album.Photos[i+1].Page
}
photoHTML, err := os.Create(path.Join(albumOutputPath, photo.Page))
if err != nil {
log.Fatalf("Failed to create photo page %s: %v", photo.Page, err)
}
err = photoTemplate.Execute(photoHTML, photo)
if err != nil {
log.Fatalf("Failed to execute photo template: %v", err)
}
}
albumIndexPath := path.Join(albumOutputPath, "index.html")
albumIndex, err := os.Create(albumIndexPath)
if err != nil {
log.Fatalf("Failed to create album index %s: %v", albumIndexPath, err)
}
defer albumIndex.Close()
albumTemplate.Execute(albumIndex, album)
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: a149cb41b9ec8995037d7fd7a07849ff5d55f586
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.