Skip to content

Commit d56bbb8

Browse files
authored
refactor: using unsafe.String and unsafe.SliceData (#21412)
1 parent 292d7b4 commit d56bbb8

File tree

6 files changed

+6
-5
lines changed

6 files changed

+6
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
4848
### Improvements
4949

5050
* (client) [#21436](https://github.com/cosmos/cosmos-sdk/pull/21436) Use `address.Codec` from client.Context in `tx.Sign`.
51+
* (internal) [#21412](https://github.com/cosmos/cosmos-sdk/pull/21412) Using unsafe.String and unsafe.SliceData.
5152

5253
### Bug Fixes
5354

internal/conv/string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func UnsafeStrToBytes(s string) []byte {
1515
// to be used generally, but for a specific pattern to delete keys
1616
// from a map.
1717
func UnsafeBytesToStr(b []byte) string {
18-
return *(*string)(unsafe.Pointer(&b))
18+
return unsafe.String(unsafe.SliceData(b), len(b))
1919
}

store/internal/conv/string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func UnsafeStrToBytes(s string) []byte {
1515
// to be used generally, but for a specific pattern to delete keys
1616
// from a map.
1717
func UnsafeBytesToStr(b []byte) string {
18-
return *(*string)(unsafe.Pointer(&b))
18+
return unsafe.String(unsafe.SliceData(b), len(b))
1919
}

store/v2/internal/conv/string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func UnsafeStrToBytes(s string) []byte {
1515
// to be used generally, but for a specific pattern to delete keys
1616
// from a map.
1717
func UnsafeBytesToStr(b []byte) string {
18-
return *(*string)(unsafe.Pointer(&b))
18+
return unsafe.String(unsafe.SliceData(b), len(b))
1919
}

x/authz/internal/conv/string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func UnsafeStrToBytes(s string) []byte {
1313
// to be used generally, but for a specific pattern to delete keys
1414
// from a map.
1515
func UnsafeBytesToStr(b []byte) string {
16-
return *(*string)(unsafe.Pointer(&b))
16+
return unsafe.String(unsafe.SliceData(b), len(b))
1717
}

x/nft/internal/conv/string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func UnsafeStrToBytes(s string) []byte {
1515
// to be used generally, but for a specific pattern to delete keys
1616
// from a map.
1717
func UnsafeBytesToStr(b []byte) string {
18-
return *(*string)(unsafe.Pointer(&b))
18+
return unsafe.String(unsafe.SliceData(b), len(b))
1919
}

0 commit comments

Comments
 (0)