Skip to content

Remove unreachable code reported by Coverity Scan - #13551

Draft
bryancall wants to merge 1 commit into
apache:masterfrom
bryancall:coverity-dead-code
Draft

Remove unreachable code reported by Coverity Scan#13551
bryancall wants to merge 1 commit into
apache:masterfrom
bryancall:coverity-dead-code

Conversation

@bryancall

Copy link
Copy Markdown
Contributor

Part 2 of 3 splitting a Coverity Scan cleanup into independently reviewable pieces. Net -13 lines; every removal is provably unreachable, so there is no behavior change.

Removals

  • YAML remap filters (RemapYamlConfig.cc, three lambdas): each tested if (ipi) where ipi is &rule->src_ip_array[rule->src_ip_cnt], the address of an array element, which is never null. The surrounding >= ACL_FILTER_MAX_* bound check already returns before the address is taken, so there is no out-of-range address either.

  • HttpCacheSM::open_write: tested master_sm && after master_sm->redirection_tries had already been dereferenced nine lines earlier in the same function. Every other method in the file dereferences it unguarded. Whether master_sm can be null at all is a separate question worth its own look; the identical guard at open_read is left in place.

  • test_RWW.cc: a block sitting after an if/else where both arms returned unconditionally. The flattened form is byte-for-byte equivalent in control flow, and the assertions that validate the writer abort are untouched.

Two additions rather than removals

  • An explicit return after a Catch2 REQUIRE(false) in test_Hdrs.cc. REQUIRE throws, so this is unreachable at runtime; it makes the exit visible to the compiler and to a reader.
  • An explicit initializer on a test member that is assigned before every read today.

Both are there to remove a construct static analysis cannot see through. Happy to drop either if you would rather not carry analyzer-appeasement in the tree.

Verification

Clean build with no new warnings and the full unit test suite passing (134/134) on Fedora, GCC 16.1.1.

Draft while CI runs.

Each removal is provably unreachable, so there is no behavior change:

  - The src_ip, src_ip_category and in_ip filter lambdas tested a pointer
    that is the address of an array element, which is never null. The
    surrounding bound check already returns before the address is taken.

  - HttpCacheSM::open_write tested master_sm after it had already been
    dereferenced nine lines earlier in the same function.

  - A block in the read-while-write cache test followed two branches that
    both returned unconditionally.

Also makes an early exit explicit after a Catch2 REQUIRE(false) in the header
test, and gives a test member an explicit initializer. Neither changes an
observed value; both remove a construct static analysis cannot see through.

Verified with a clean build (no new warnings) and the full unit test suite on
Fedora, GCC 16.1.1.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes Coverity-reported unreachable code paths across remap YAML ACL parsing, cache write handling, and unit tests, aiming to reduce dead branches without changing runtime behavior.

Changes:

  • Simplifies YAML remap filter parsing by removing always-true pointer checks and unconditionally updating the corresponding counters/valid flags after bounds checks.
  • Removes an ineffective master_sm && guard in HttpCacheSM::open_write where master_sm is already dereferenced earlier in the function.
  • Cleans up unreachable unit test control-flow and adds small analyzer-friendly adjustments (explicit return after REQUIRE(false), explicit member initialization).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/proxy/http/remap/RemapYamlConfig.cc Removes unreachable if (ipi) branches after taking addresses of fixed-array elements and keeps existing bounds checks.
src/proxy/http/HttpCacheSM.cc Drops redundant master_sm && check in open_write after earlier unconditional dereferences of master_sm.
src/proxy/hdrs/unit_tests/test_Hdrs.cc Adds an explicit return; after REQUIRE(false) to make the early-exit clear to readers/analysis.
src/iocore/cache/unit_tests/test_RWW.cc Removes code after unconditional returns and makes the writer-abort intent explicit once the reader starts.
plugins/experimental/jax_fingerprint/ja4h/test.cc Explicitly initializes a test member (_version{}) to satisfy static analysis.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants