github-vet / github-vet/rangeloop-pointer-findings
badu/side_by_side_gorm: main.go; 32 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [badu/side_by_side_gorm](https://www.github.com/badu/side_by_side_gorm) at [main.go](https://github.com/badu/side_by_side_gorm/blob/546d64c2efd6df719f8d9e2b616bcb72bc3bb8ee/main.go#L743-L774)
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 vtime was used in a composite literal at line 745
[Click here to see the code in its original context.](https://github.com/badu/side_by_side_gorm/blob/546d64c2efd6df719f8d9e2b616bcb72bc3bb8ee/main.go#L743-L774)
Click here to show the 32 line(s) of Go which triggered the analyzer.
```go
for index, vtime := range times {
name := "time_with_zone_" + strconv.Itoa(index)
user := new_types.User{Name: name, Birthday: &vtime}
if !NewDialectHasTzSupport() {
// If our driver dialect doesn't support TZ's, just use UTC for everything here.
utcBirthday := user.Birthday.UTC()
user.Birthday = &utcBirthday
}
new_types.TestDB.Save(&user)
expectedBirthday := "2013-02-18 17:51:49 +0000"
foundBirthday := user.Birthday.UTC().Format(format)
if foundBirthday != expectedBirthday {
t.Errorf("User's birthday should not be changed after save for name=%s, expected bday=%+v but actual value=%+v", name, expectedBirthday, foundBirthday)
}
var findUser, findUser2, findUser3 new_types.User
new_types.TestDB.First(&findUser, "name = ?", name)
foundBirthday = findUser.Birthday.UTC().Format(format)
if foundBirthday != expectedBirthday {
t.Errorf("User's birthday should not be changed after find for name=%s, expected bday=%+v but actual value=%+v", name, expectedBirthday, foundBirthday)
}
if new_types.TestDB.Where("id = ? AND birthday >= ?", findUser.Id, user.Birthday.Add(-time.Minute)).First(&findUser2).RecordNotFound() {
t.Errorf("User should be found")
}
if !new_types.TestDB.Where("id = ? AND birthday >= ?", findUser.Id, user.Birthday.Add(time.Minute)).First(&findUser3).RecordNotFound() {
t.Errorf("User should not be found")
}
}
```
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: 546d64c2efd6df719f8d9e2b616bcb72bc3bb8ee
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.