Repository navigation
Conversation
With -DNDEBUG, assert(0) in the default case of the buffer seek callbacks compiles away, so newOffset is read uninitialized and gcc warns with -Wmaybe-uninitialized. Return -1 (the error value the callback already uses for an out-of-range offset) after the assert, in ZSTD_seekable_seek_buff() and the copy in seekable_tests.c.
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What and why
Fixes #4756.
In
ZSTD_seekable_seek_buff()(contrib/seekable_format/zstdseek_decompress.c), thedefault:case ofswitch (origin)is onlyassert(0). With-DNDEBUGthe assert is compiled out, sonewOffsetis read uninitialized and gcc warns. This PR addsreturn -1;after the assert.-1is what the function already returns when the new offset is out of range.assert(0)is kept, so debug builds still catch the case.seekBuffWithTotal()incontrib/seekable_format/tests/seekable_tests.cis a copy of the same function with the same defect, so it gets the same one-line change.originis alwaysSEEK_SET,SEEK_CURorSEEK_ENDat the library's call sites, so no runtime input reachesdefault:. The fix only removes the compiler diagnostic.The warning is a compile-time diagnostic, so the reproducer is a compiler command (gcc 15.2.0):
Before:
After: no output, exit 0. The same command with
-DXXH_NAMESPACE=ZSTD_oncontrib/seekable_format/tests/seekable_tests.cno longer reportsnewOffseteither.make -C contrib/seekable_format/tests testpasses (all 5 seekable tests), and so domake checkandmake test.Checklist
A gain in one configuration is not a general gain: see the Performance section of CONTRIBUTING.md.
Tools used
An AI coding assistant (Claude Code) wrote the change, ran the checks above, and wrote this description.
I am new to open source, and this pull request was made with AI assistance.