seekable_format warning with -DNDEBUG: potential uninitialised local variable newOffset used
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- build-system
Research direction
Locate the seekable_format function and inspect the switch around the assert and newOffset use, then reproduce the warning with MSVC /W4 /O2 /DNDEBUG through the CMake build. The work is done when seekable_format and the resulting static library compile without uninitialised-variable warnings under the reported flags.
Written by the indexing model from the issue text.
Description
Describe the bug
When seekable_format is compiled with -DNDEBUG (common for release builds), the assert inside the switch is eliminated. As a result the "unreachable" code from lines 190 onwards become reachable and the compiler correctly determines that in line 193 the variable is used uninitialised triggering a warning. Since compiling with DNDEBUG is a valid way to reduce run-time overhead in release environments, I suggest this use-of-uninitialised-variable should be mitigated without the use of assert(), perhaps by return -1; in the default case below the assert(0);
To Reproduce
Steps to reproduce the behavior:
- Compile seekable_format with -DNDEBUG.
Expected behavior
No warnings are expected during compilation of seekable format or linking of a static library file resulting from such compilation.
Compilation environment:
- OS: Windows
- Version 1.5.7, also head of MAIN
- Compiler MSVC 19.29.30159.0
- Flags /W4 /O2 /DNDEBUG
- Build system CMake
- Dominant language
- C
- Stars
- 27.9k
- Forks
- 2.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from facebook/zstd
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100