Skip to content

Commit

Permalink
internal/bytealg: extend memchr result correctly on wasm
Browse files Browse the repository at this point in the history
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 <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
Zxilly authored and randall77 committed Jul 17, 2024
1 parent 3557118 commit 90c6558
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/bytes/bytes_js_wasm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build js && wasm

package bytes_test

import (
"bytes"
"testing"
)

func TestIssue65571(t *testing.T) {
b := make([]byte, 1<<31+1)
b[1<<31] = 1
i := bytes.IndexByte(b, 1)
if i != 1<<31 {
t.Errorf("IndexByte(b, 1) = %d; want %d", i, 1<<31)
}
}
4 changes: 2 additions & 2 deletions src/internal/bytealg/indexbyte_wasm.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TEXT ·IndexByte(SB), NOSPLIT, $0-40
I64Load b_len+8(FP)
I32WrapI64
Call memchr<>(SB)
I64ExtendI32S
I64ExtendI32U
Set R0

Get SP
Expand All @@ -35,7 +35,7 @@ TEXT ·IndexByteString(SB), NOSPLIT, $0-32
I64Load s_len+8(FP)
I32WrapI64
Call memchr<>(SB)
I64ExtendI32S
I64ExtendI32U
Set R0

I64Const $-1
Expand Down

0 comments on commit 90c6558

Please sign in to comment.