-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(y): shall always return empty slice rather than nil #2245
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -95,7 +95,11 @@ func OpenTruncFile(filename string, sync bool) (*os.File, error) { | |
|
|
||
| // SafeCopy does append(a[:0], src...). | ||
| func SafeCopy(a, src []byte) []byte { | ||
| return append(a[:0], src...) | ||
| b := append(a[:0], src...) | ||
| if b == nil { | ||
| return []byte{} | ||
| } | ||
| return b | ||
| } | ||
|
|
||
| // Copy copies a byte slice and returns the copied slice. | ||
|
|
@@ -134,7 +138,7 @@ func CompareKeys(key1, key2 []byte) int { | |
|
|
||
| // ParseKey parses the actual key from the key bytes. | ||
| func ParseKey(key []byte) []byte { | ||
| if key == nil { | ||
| if len(key) < 8 { | ||
|
Collaborator
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. @kooltuoehias I added this sanity check here. In practice, keys processed anywhere in badger will always have byte data, but because SafeCopy does now produce zero length slices and
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.
Many thanks ! Things goes really quick here ! |
||
| return nil | ||
| } | ||
|
|
||
|
|
||
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.
These mistakenly got commented out in a prior merge.
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.
Thanks for catching the edge case with Entry.Key and the quick merge! Happy to contribute.