-
Notifications
You must be signed in to change notification settings - Fork 456
fix(gnovm): avoid panic on assertion over nil slice #5780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
3f2565d
4b00b2b
a0f2311
c5ff5af
f6852e9
ea50134
8bec3e7
65882c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| gno run . | ||
|
|
||
| -- main.gno -- | ||
| // Copyright 2022 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. | ||
|
|
||
| // Test case where a slice of a user-defined byte type (not uint8 or byte) is | ||
| // converted to a string. Same for slice of runes. | ||
|
|
||
| package main | ||
|
|
||
| type MyByte byte | ||
|
|
||
| type MyRune rune | ||
|
|
||
| func main() { | ||
| var y []MyByte | ||
| _ = string(y) | ||
|
|
||
| var z []MyRune | ||
| _ = string(z) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -787,8 +787,10 @@ func (m *Machine) doOpConvert() { | |
| } else if t.Kind() == StringKind { | ||
| // runes ([]int32) → string | ||
| if st, ok := baseOf(xv.T).(*SliceType); ok && st.Elt.Kind() == Int32Kind { | ||
| sv := xv.V.(*SliceValue) | ||
| m.incrCPU(OpCPUSlopeConvertRunesStr * int64(sv.GetLength())) | ||
| if xv.V != nil { | ||
| sv := xv.V.(*SliceValue) | ||
| m.incrCPU(OpCPUSlopeConvertRunesStr * int64(sv.GetLength())) | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a philosophical question but should we increment the CPU for converting an empty string (0 length) ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: m.incrCPU(OpCPUSlopeConvertRunesStr * int64(xv.GetLength()))This also mirrors the string→runes branch above, which is nil-safe for the same reason (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done here thanks for the review: 8bec3e7 |
||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit on placement: this txtar runs
gno run .but lives intestdata/test/, where every other script exercises thegno testsubcommand (the testdata subdirs are grouped per subcommand). Since this is a VM-behavior regression rather than a CLI one, the canonical home would be a filetest ingnovm/tests/files/with an// Output:comment — lighter weight (runs underTestFilesinstead of spinning up the CLI), and the issue body is already written in that format, so it converts directly.Optional while you're at it: only the
[]MyRuneline actually reaches the buggy branch ([]MyBytenever enters theInt32Kindgas path). Adding a plainvar r []rune; _ = string(r)would document that the bug wasn't specific to declared types.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed here 8bec3e7
For the change on the type I could do it but this file references Golang tests so I don't know if a good idea to modify it let me know if you still want to do the change and I'll do it