瀏覽代碼

fix: prevent index out of range panic on 32-bit platforms

On 32-bit architectures (e.g. ARM7), int is 32 bits wide.
Casting a uint32 hash value to int can overflow, producing a
negative number. Go's modulo operator preserves the sign, so
the channel index can become -1, causing a panic.

Perform the modulo in uint32 space before indexing to ensure
the result is always non-negative.

Fixes #413
tags/v2.2.5^2^2
Alexey Dolotov 1 月之前
父節點
當前提交
01402bdba2
共有 1 個檔案被更改,包括 1 行新增1 行删除
  1. 1
    1
      events/event_stream.go

+ 1
- 1
events/event_stream.go 查看文件

@@ -38,7 +38,7 @@ func (e EventStream) Send(ctx context.Context, evt mtglib.Event) {
38 38
 	select {
39 39
 	case <-ctx.Done():
40 40
 	case <-e.ctx.Done():
41
-	case e.chans[int(chanNo)%len(e.chans)] <- evt:
41
+	case e.chans[chanNo%uint32(len(e.chans))] <- evt:
42 42
 	}
43 43
 }
44 44
 

Loading…
取消
儲存