-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix issue 26 #27
Closed
Closed
fix issue 26 #27
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80a0229
fix issue 26
chavacava b841c18
clearer test implementation
chavacava 0bdc91a
make it explicit here that we primarily intend this case for io.SeekEnd
chavacava 11ea917
check err in the deferred seek to initial pos
chavacava 3e00f49
Merge branch 'fix-26' of https://github.com/chavacava/kaitai_struct_g…
chavacava fc91f26
removes unnecessary trailing newline
chavacava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 tool https://github.com/golangci/golangci-lint noticed this problem:
This might potentially lead to a bug that this call fails, but because its error return value is ignored,
k.Size()
will happily returnerr == nil
(despite the fact that the stream pointer failed to return to the original position for some reason and we're clearly in a situation of failure).I think the code should be like this:
See https://yourbasic.org/golang/defer/#use-func-to-return-a-value and https://blog.learngoprogramming.com/5-gotchas-of-defer-in-go-golang-part-iii-36a1ab3d6ef1#afb5.
Could you please adjust the tests to check this case as well?
Perhaps we can make the
failingReader
more generic by restoring its normal behavior (i.e.io.SeekEnd
behaving as normal, not settingpos
to-1
) and instead passing a param in it (e.g.numSeeksLimit
) that limits the number of succeedingSeek()
calls. Then we can just go iterate0..(numSeeksThatSizeMethodDoes - 1)
and check for each limit that theSize()
function always returns an error and restores the stream position to its original state.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.
I've added two test cases: