github-vet / github-vet/rangeloop-pointer-findings

mike182uk/snpt: cmd/snpt/command/sync/sync.go; 37 LoC

Open
#12,774 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [mike182uk/snpt](https://www.github.com/mike182uk/snpt) at [cmd/snpt/command/sync/sync.go](https://github.com/mike182uk/snpt/blob/6c10e07582a97307cb7b6a09849eae3d5cfb5e48/cmd/snpt/command/sync/sync.go#L70-L106)

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.

> reference to file was used in a composite literal at line 71

[Click here to see the code in its original context.](https://github.com/mike182uk/snpt/blob/6c10e07582a97307cb7b6a09849eae3d5cfb5e48/cmd/snpt/command/sync/sync.go#L70-L106)

Click here to show the 37 line(s) of Go which triggered the analyzer.

```go
for filename, file := range gist.Files {
fileContent, err := gistRetriever.RetrieveGistFileContent(&file)

if err != nil {
printProgressError(spinner, out, err.Error())

continue
}

h := md5.New()
_, err = h.Write([]byte(*file.RawURL))

if err != nil {
printProgressError(spinner, out, "Failed to generate ID for gist: %s", *file.RawURL)

continue
}

gistID := hex.EncodeToString(h.Sum(nil))

snpt := pb.Snippet{
Id: gistID,
Filename: string(filename),
Description: *gist.Description,
Content: fileContent,
}

err = snptStore.Put(&snpt)

if err != nil {
printProgressError(spinner, out, "Failed to save snippet: %s to the database", snpt.Filename)

continue
}

gistCount++
}

```

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: 6c10e07582a97307cb7b6a09849eae3d5cfb5e48

Contributor guide

No contributing guide indexed for this repository

Research direction

Open cmd/snpt/command/sync/sync.go at lines 70-106 and read the analyzer message about the range-loop variable reference. Decide whether the report represents a bug, mitigated behavior, or desirable behavior, then leave the corresponding reaction; completion is the selected classification.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.