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
This commit is contained in:
Alexey Dolotov
2026-03-28 22:31:47 +03:00
parent cc4b6ce2f4
commit 01402bdba2
+1 -1
View File
@@ -38,7 +38,7 @@ func (e EventStream) Send(ctx context.Context, evt mtglib.Event) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
case <-e.ctx.Done(): case <-e.ctx.Done():
case e.chans[int(chanNo)%len(e.chans)] <- evt: case e.chans[chanNo%uint32(len(e.chans))] <- evt:
} }
} }