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

selinplus/go-dingtalk: routers/api/fsdj/highlight.go; 14 LoC

Open
#15,140 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 [selinplus/go-dingtalk](https://www.github.com/selinplus/go-dingtalk) at [routers/api/fsdj/highlight.go](https://github.com/selinplus/go-dingtalk/blob/87146958b269c7f9e1eb6198fb6f6efc1ebdf579/routers/api/fsdj/highlight.go#L204-L217)

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 star was used in a composite literal at line 212

[Click here to see the code in its original context.](https://github.com/selinplus/go-dingtalk/blob/87146958b269c7f9e1eb6198fb6f6efc1ebdf579/routers/api/fsdj/highlight.go#L204-L217)

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

```go
for _, star := range hlt.StudyHltStars {
user, err := models.GetUserdemoByUserid(star.UserID)
if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_GET_USER_FAIL,
fmt.Sprintf("根据userid:%s 获取人员信息错误:%v", star.UserID, err))
return
}
stars = append(stars, &HltStarResp{
StudyHltStar: &star,
Avatar: user.Avatar,
Name: user.Name,
Mobile: user.Mobile,
})
}

```

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: 87146958b269c7f9e1eb6198fb6f6efc1ebdf579

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with routers/api/fsdj/highlight.go at lines 204-217 and inspect the analyzer's warning about the reference used in the composite literal. Check how the loop builds stars and whether the referenced value remains correct for each response entry. Done means the reported issue is addressed without changing the intended response data.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.