fix iter value safe copy
This commit is contained in:
@@ -30,3 +30,5 @@ go.work.sum
|
||||
# Editor/IDE
|
||||
# .idea/
|
||||
# .vscode/
|
||||
|
||||
__debug_bin*
|
||||
@@ -199,10 +199,7 @@ func (r *reactions) addHot(k []byte, delta int) {
|
||||
}
|
||||
|
||||
cnt.mu.Lock()
|
||||
val := int64(cnt.val) + int64(delta)
|
||||
if val < 0 {
|
||||
val = 0
|
||||
}
|
||||
val := max(int64(cnt.val)+int64(delta), 0)
|
||||
cnt.val = uint64(val)
|
||||
|
||||
if !cnt.jobRunning {
|
||||
|
||||
@@ -78,9 +78,12 @@ func (s *subscriptions) OfDomestic(user string, limit, offset int) ([]database.S
|
||||
keyParts := bytes.Split(iter.Key(), []byte(":"))
|
||||
targetEmail := string(keyParts[len(keyParts)-1])
|
||||
|
||||
sig := make([]byte, len(iter.Value()))
|
||||
copy(sig, iter.Value())
|
||||
|
||||
subs = append(subs, database.Subscription{
|
||||
User: targetEmail,
|
||||
Signature: iter.Value(),
|
||||
Signature: sig,
|
||||
})
|
||||
|
||||
if len(subs) >= limit {
|
||||
@@ -108,9 +111,12 @@ func (s *subscriptions) ToForeign(targetEmail string, limit, offset int) ([]data
|
||||
keyParts := bytes.Split(iter.Key(), []byte(":"))
|
||||
subscriberName := string(keyParts[len(keyParts)-1])
|
||||
|
||||
sig := make([]byte, len(iter.Value()))
|
||||
copy(sig, iter.Value())
|
||||
|
||||
subs = append(subs, database.Subscription{
|
||||
User: subscriberName,
|
||||
Signature: iter.Value(),
|
||||
Signature: sig,
|
||||
})
|
||||
|
||||
if len(subs) >= limit {
|
||||
@@ -147,10 +153,7 @@ func (s *subscriptions) addHot(k []byte, delta int) {
|
||||
}
|
||||
|
||||
cnt.mu.Lock()
|
||||
val := int64(cnt.val) + int64(delta)
|
||||
if val < 0 {
|
||||
val = 0
|
||||
}
|
||||
val := max(int64(cnt.val)+int64(delta), 0)
|
||||
cnt.val = uint64(val)
|
||||
|
||||
if !cnt.jobRunning {
|
||||
|
||||
Reference in New Issue
Block a user