Skip to content

Fix for potentially uninitialized local variable ft used.#2043

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
phprus:functable-init-1
Dec 7, 2025
Merged

Fix for potentially uninitialized local variable ft used.#2043
Dead2 merged 1 commit intozlib-ng:developfrom
phprus:functable-init-1

Conversation

@phprus
Copy link
Copy Markdown
Contributor

@phprus phprus commented Dec 6, 2025

The FUNCTABLE_VERIFY_ASSIGN macro reads values from ft and checks that they are not NULL, but the ft variable is not initialized.

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 6, 2025

Walkthrough

The change adds memory initialization to functable.c by zeroing out a local functable_s instance using memset() before pointer assignments and validations, ensuring all fields start in a known state.

Changes

Cohort / File(s) Summary
Memory Initialization
functable.c
Initialize local functable_s instance to zero with memset() before subsequent pointer assignments and field validations

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: initializing the uninitialized local variable ft to fix a potential bug.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem that the fix addresses: the uninitialized ft variable issue.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2cd66c and 88b8a9d.

📒 Files selected for processing (1)
  • functable.c (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: KungFuJesus
Repo: zlib-ng/zlib-ng PR: 1802
File: chunkset_tpl.h:135-135
Timestamp: 2024-10-07T21:23:13.401Z
Learning: In the `CHUNKMEMSET` function within `chunkset_tpl.h`, extra bounds checks are avoided to maintain performance in critical code sections. Branching is minimized to prevent negative impacts on speculative execution. The variable `len` is enforced with `safelen` early on.
📚 Learning: 2025-04-15T09:30:10.081Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1904
File: arch/riscv/Makefile.in:12-14
Timestamp: 2025-04-15T09:30:10.081Z
Learning: Feature detection modules like riscv_features.c should not be compiled with feature-specific flags (like RVVFLAG) because they need to be compilable on all systems regardless of feature support. These modules perform runtime detection and must initialize feature availability flags to zero on unsupported systems.

Applied to files:

  • functable.c
🧬 Code graph analysis (1)
functable.c (1)
functable.h (1)
  • adler (26-41)
🔇 Additional comments (1)
functable.c (1)

71-76: Correct fix for undefined behavior from uninitialized local variable.

The memset() initialization ensures all fields of the ft struct start in a known state (NULL) before conditional assignments and validation checks. Without this, fields that aren't assigned in any of the compile-time or runtime conditional blocks would contain garbage values, causing undefined behavior when read by the FUNCTABLE_VERIFY_ASSIGN macro at lines 356–368.

The placement is correct—right after variable declarations and before any field assignments—and the size calculation is accurate for the struct. This is essential for correct operation, as the verification checks rely on all fields being either assigned to valid function pointers or remaining NULL to signal initialization failure.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.32%. Comparing base (e2cd66c) to head (88b8a9d).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2043      +/-   ##
===========================================
+ Coverage    80.64%   82.32%   +1.68%     
===========================================
  Files          162      162              
  Lines        12883    12923      +40     
  Branches      3174     3174              
===========================================
+ Hits         10389    10639     +250     
+ Misses        1455     1226     -229     
- Partials      1039     1058      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@mtl1979 mtl1979 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Dead2 Dead2 merged commit b3ade58 into zlib-ng:develop Dec 7, 2025
190 of 191 checks passed
@Dead2 Dead2 mentioned this pull request Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants