From 00f1f7b96ea2a161a25210ceeb9d5a3fc41b47eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Afonso=20Janu=C3=A1rio?= Date: Fri, 4 Sep 2026 22:23:08 +0100 Subject: [PATCH] Return -1 from the unreachable default case in seek_buff seekable_tests.c's seekBuffWithTotal and zstdseek_decompress.c's ZSTD_seekable_seek_buff both fall into a default: assert(0) case for an unsupported seek origin, but never return afterwards. When built with NDEBUG the assert is a no-op, so the switch falls through and newOffset gets compared and stored uninitialized. GCC and Clang both flag this as a real used-uninitialized warning on -O2/-DNDEBUG builds. The default case isn't reachable through any of the library's own call sites (origin is always SEEK_SET/SEEK_CUR/SEEK_END), so there's no runtime input that exercises the fix; verified instead by compiling zstdseek_decompress.c with clang -Wall -Wextra -DNDEBUG -O2 and confirming the used-uninitialized warning is present before the fix and gone after, then rebuilding and running the full contrib/seekable_format/tests suite (all 5 tests pass) with the fix in place. --- contrib/seekable_format/tests/seekable_tests.c | 1 + contrib/seekable_format/zstdseek_decompress.c | 1 + 2 files changed, 2 insertions(+) diff --git a/contrib/seekable_format/tests/seekable_tests.c b/contrib/seekable_format/tests/seekable_tests.c index 809ea6425eb..2c014b73eda 100644 --- a/contrib/seekable_format/tests/seekable_tests.c +++ b/contrib/seekable_format/tests/seekable_tests.c @@ -45,6 +45,7 @@ static int seekBuffWithTotal(void* opaque, long long offset, int origin) break; default: assert(0); /* not possible */ + return -1; /* keeps newOffset from being read uninitialised when NDEBUG strips the assert */ } if (newOffset > buff->size) { return -1; diff --git a/contrib/seekable_format/zstdseek_decompress.c b/contrib/seekable_format/zstdseek_decompress.c index ab9088a1061..7de90903a73 100644 --- a/contrib/seekable_format/zstdseek_decompress.c +++ b/contrib/seekable_format/zstdseek_decompress.c @@ -186,6 +186,7 @@ static int ZSTD_seekable_seek_buff(void* opaque, long long offset, int origin) break; default: assert(0); /* not possible */ + return -1; /* keeps newOffset from being read uninitialised when NDEBUG strips the assert */ } if (newOffset > buff->size) { return -1;