github-vet / github-vet/rangeloop-pointer-findings
fengzhimiwu/bbq: all/loyocloud-workerpool/handlers/into/importCustomer.go; 183 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [fengzhimiwu/bbq](https://www.github.com/fengzhimiwu/bbq) at [all/loyocloud-workerpool/handlers/into/importCustomer.go](https://github.com/fengzhimiwu/bbq/blob/e4d3ef6c4b526911f20908b7e777c96c96abfc81/all/loyocloud-workerpool/handlers/into/importCustomer.go#L843-L1025)
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 originCus used in defer or goroutine at line 993
[Click here to see the code in its original context.](https://github.com/fengzhimiwu/bbq/blob/e4d3ef6c4b526911f20908b7e777c96c96abfc81/all/loyocloud-workerpool/handlers/into/importCustomer.go#L843-L1025)
Click here to show the 183 line(s) of Go which triggered the analyzer.
```go
for _, originCus := range *originCustomers {
//ini status name
if name, ok := getStatusNameViaId(ic.sysCusTag, originCus.StatusId); ok {
originCus.StatusName = name
}
if name, ok := getStatusNameViaId(ic.sysCusTag, cus.StatusId); ok {
cus.StatusName = name
}
//Debug============================================
if debugEnable {
beego.Info("originCus.StatusName is: ", originCus.StatusName, "cus.StatusName is: ", cus.StatusName, "erId:", ic.erId)
}
//=================================================
updateCust := &customer.Customer{}
*updateCust = *originCus
//update location
updateCust.Location = &customer.Location{}
updateCust.Location.Address = cus.Location.Address
//update Contacts
var (
updated bool = false
defaultNewContact *customer.Contact
defaultOldContact *customer.Contact
)
for _, item := range cus.Contacts {
if item.IsDefault {
defaultNewContact = &customer.Contact{}
*defaultNewContact = *item
break
}
}
for _, item := range updateCust.Contacts {
if item.IsDefault {
defaultOldContact = &customer.Contact{}
*defaultOldContact = *item
}
}
if len(cus.Contacts) > 0 {
for _, item1 := range cus.Contacts {
if item1.IsDefault {
for _, item2 := range updateCust.Contacts {
if item2.IsDefault {
*item2 = *item1 //update default contact
updated = true
break
}
}
} else {
updateCust.Contacts = append(updateCust.Contacts, item1)
}
}
if !updated && (defaultNewContact != nil) {
updateCust.Contacts = append([]*customer.Contact{defaultNewContact}, updateCust.Contacts...)
}
//scan default one, make sure only one item is set as default
foundDefault := false
for _, item := range updateCust.Contacts {
if foundDefault {
item.IsDefault = false
continue
}
if item.IsDefault {
foundDefault = true
}
}
if len(updateCust.Contacts) > 0 && (!foundDefault) {
defaultNewContact = updateCust.Contacts[0]
updateCust.Contacts[0].IsDefault = true
}
}
var doBulkingCensus bool = false
oldTags := getCusTags(updateCust)
newAddTags := getNewTagItems(updateCust, cus)
doBulkingCensus = (len(newAddTags) > 0) && (!ic.isPublic)
//beego.Info("=========================")
//beego.Info("doBulkingCensus is: ", doBulkingCensus)
//if doBulkingCensus {
//beego.Info("oldTags: ", utils.DocOfDataStruct(updateCust.Tags))
//beego.Info("newTags: ", utils.DocOfDataStruct(cus.Tags))
//fbeego.Info("newAddTags: ", utils.DocOfDataStruct(newAddTags))
//}
//beego.Info("=========================")
//update Tags
updateCust.Tags = []*customer.CustomerTag{}
if len(cus.Tags) > 0 {
for _, item := range cus.Tags {
updateCust.Tags = append(updateCust.Tags, item)
}
}
//update SignTag
if updateCust.CustomerType == customer.SIGNED_CUSTOMER && cus.CustomerType == customer.SIGNED_CUSTOMER {
updateCust.SignedTags = []*customer.CustomerTag{}
if len(cus.SignedTags) > 0 {
for _, item := range cus.SignedTags {
updateCust.SignedTags = append(updateCust.SignedTags, item)
}
}
}
//update ExtensionDatas
updateCust.ExtensionDatas = []*tmodels.DynamicData{}
if len(cus.ExtensionDatas) > 0 {
for _, item := range cus.ExtensionDatas {
updateCust.ExtensionDatas = append(updateCust.ExtensionDatas, item)
}
}
/////TODO: 简单字符串更新应该用反射来做///////////
updateCust.Name = cus.Name
updateCust.Summary = cus.Summary
updateCust.WebSite = cus.WebSite
///////////////////////////////////////////////////
//update status id
var doRecycle bool = false
if updateCust.StatusId.Hex() != cus.StatusId.Hex() {
if (updateCust.CustomerType == customer.DEV_CUSTOMER) && (!ic.isPublic) {
doRecycle = true
}
updateCust.StatusId = cus.StatusId
updateCust.StatusName = cus.StatusName
}
//update time stamp
updateCust.UpdatedAt = cus.UpdatedAt
err := o.Update(updateCust, nil)
if err == nil {
go ic.statisticAndLog(updateCust, newAddTags, false, doBulkingCensus)
//公海客户不需要事后给负责人发送通知
if updateCust.Lock {
countOverrideRecord(ic, updateCust.Id, updateCust.Owner.Id)
}
if doRecycle {
ic.appendCusIds(&[]bson.ObjectId{updateCust.Id})
}
go func(cus *customer.Customer) {
defer func() {
if err := recover(); err != nil {
debug.PrintStack()
beego.Error("*******Panic error:", err)
}
}()
customer.CommonOperator(updateCust.CompanyId, cus.Creator.Id, updateCust.Id, cus.Creator.RealName, originCus, updateCust, operatelog.ImportCover, nil)
customer.InsertToEsByIds(cus.CompanyId, []bson.ObjectId{cus.Id})
oldContact := &customer.Contact{}
if defaultOldContact != nil {
oldContact = defaultOldContact
}
if defaultNewContact != nil {
originkey, _ := customer.ContactKeyVal(oldContact)
newkey, newval := customer.ContactKeyVal(defaultNewContact)
operatelog.AddLog(originkey, newkey, newval, operatelog.Customer, operatelog.ImportCover, updateCust.Id.Hex(), cus.Creator.Id.Hex(), cus.Creator.RealName, updateCust.CompanyId)
}
//log tag changed
newTags := getCusTags(cus)
logTagChange(updateCust.CompanyId, cus.Creator.Id, updateCust.Id, oldTags, newTags, cus.Creator.RealName)
//log new added multi-contact
for _, item := range cus.Contacts {
if item.IsDefault {
continue
}
newKey, newVal := customer.ContactKeyVal(item)
operatelog.AddLog(newKey, nil, newVal, operatelog.Customer, operatelog.CreatContact, updateCust.Id.Hex(), cus.Creator.Id.Hex(), cus.Creator.RealName, updateCust.CompanyId)
//operatelog.AddLog(originkey, nil, oldval, operatelog.Customer, operatelog.CreatContact, id.Hex(), currentUser.Id.Hex(), currentUser.RealName, currentUser.CompanyId)
}
}(cus)
} else {
return err
}
}
```
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: e4d3ef6c4b526911f20908b7e777c96c96abfc81
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.