fix iter value safe copy

This commit is contained in:
d1nch8g
2026-05-11 12:17:48 +07:00
parent 83627be743
commit 34b3fc7ec4
3 changed files with 12 additions and 10 deletions
+2
View File
@@ -30,3 +30,5 @@ go.work.sum
# Editor/IDE
# .idea/
# .vscode/
__debug_bin*
+1 -4
View File
@@ -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 {
+9 -6
View File
@@ -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 {