Skip to content

Commit 90c6558

Browse files
Zxillyrandall77
authored andcommitted
internal/bytealg: extend memchr result correctly on wasm
The mem address should be regarded as uint32. Fixes #65571 Change-Id: Icee38d11f2d93eeca7d50b2e133159e321daeb90 GitHub-Last-Rev: c2568b1 GitHub-Pull-Request: #68400 Reviewed-on: https://go-review.googlesource.com/c/go/+/597955 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 3557118 commit 90c6558

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/bytes/bytes_js_wasm_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build js && wasm
6+
7+
package bytes_test
8+
9+
import (
10+
"bytes"
11+
"testing"
12+
)
13+
14+
func TestIssue65571(t *testing.T) {
15+
b := make([]byte, 1<<31+1)
16+
b[1<<31] = 1
17+
i := bytes.IndexByte(b, 1)
18+
if i != 1<<31 {
19+
t.Errorf("IndexByte(b, 1) = %d; want %d", i, 1<<31)
20+
}
21+
}

src/internal/bytealg/indexbyte_wasm.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEXT ·IndexByte(SB), NOSPLIT, $0-40
1212
I64Load b_len+8(FP)
1313
I32WrapI64
1414
Call memchr<>(SB)
15-
I64ExtendI32S
15+
I64ExtendI32U
1616
Set R0
1717

1818
Get SP
@@ -35,7 +35,7 @@ TEXT ·IndexByteString(SB), NOSPLIT, $0-32
3535
I64Load s_len+8(FP)
3636
I32WrapI64
3737
Call memchr<>(SB)
38-
I64ExtendI32S
38+
I64ExtendI32U
3939
Set R0
4040

4141
I64Const $-1

0 commit comments

Comments
 (0)