-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-14876: [Go] Handling Crashes in C Data interface #14877
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
Conversation
| for i := range arr.Data().Buffers() { | ||
| buf := arr.Data().Buffers()[i] | ||
| if buf == nil { | ||
| if buf == nil || buf.Len() == 0 { |
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.
This doesn't seem mandatory either.
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.
The reason for this is line 374 below. In the case where buf.Len() == 0 there is no allocated data to grab a pointer to via &buf.Bytes()[0] and you end up panic'ing with an error of attempting to get index 0 of a 0 length slice. Thus if we create an empty array, it's better to just use a nil pointer.
The alternative here would be to use &buf.Buf()[0] instead, which points at the reserved bytes (since creating a new buffer will, by default, automatically reserve 64 bytes if it wasn't expanded) but I thought it better to not force us to keep that memory around for a 0 length array.
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.
Sounds ok to me.
Uh oh!
There was an error while loading. Please reload this page.