From 153e59e3984a481d9f4526c95e4f6479e13e6782 Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Fri, 14 Aug 2026 11:21:39 -0700 Subject: [PATCH] Remove unreachable code reported by Coverity Scan 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. --- .../experimental/jax_fingerprint/ja4h/test.cc | 2 +- src/iocore/cache/unit_tests/test_RWW.cc | 15 +++------------ src/proxy/hdrs/unit_tests/test_Hdrs.cc | 2 ++ src/proxy/http/HttpCacheSM.cc | 2 +- src/proxy/http/remap/RemapYamlConfig.cc | 18 ++++++------------ 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/plugins/experimental/jax_fingerprint/ja4h/test.cc b/plugins/experimental/jax_fingerprint/ja4h/test.cc index 3d1abb50224..2b0c17f755d 100644 --- a/plugins/experimental/jax_fingerprint/ja4h/test.cc +++ b/plugins/experimental/jax_fingerprint/ja4h/test.cc @@ -105,7 +105,7 @@ class MockDatasource : public Datasource private: std::string _method; - int _version; + int _version{}; std::map _fields{}; }; diff --git a/src/iocore/cache/unit_tests/test_RWW.cc b/src/iocore/cache/unit_tests/test_RWW.cc index ee9d0b97782..70fd116ffd7 100644 --- a/src/iocore/cache/unit_tests/test_RWW.cc +++ b/src/iocore/cache/unit_tests/test_RWW.cc @@ -240,20 +240,11 @@ class CacheRWWErrorTest : public CacheRWWTest this->_read_event = this_ethread()->schedule_imm(this->_rt); } return; - } else { - this->close_write(100); - return; - } - - // write at least one fragment before read it - if (this->_latest_fragments == this->_wt->vc->fragment) { - base->reenable(); - return; } - this->_latest_fragments = this->_wt->vc->fragment; - this->_rt->reenable(); - break; + // Once the reader has started, abort the writer to exercise the error path. + this->close_write(100); + return; case VC_EVENT_WRITE_COMPLETE: REQUIRE(!"should not happen because the writer aborted"); diff --git a/src/proxy/hdrs/unit_tests/test_Hdrs.cc b/src/proxy/hdrs/unit_tests/test_Hdrs.cc index 71d52af9a23..a94f81a405d 100644 --- a/src/proxy/hdrs/unit_tests/test_Hdrs.cc +++ b/src/proxy/hdrs/unit_tests/test_Hdrs.cc @@ -1131,6 +1131,8 @@ TEST_CASE("HdrTest", "[proxy][hdrtest]") if (cc_field == nullptr) { std::printf("FAILED: missing Cache-Control header\n\n"); REQUIRE(false); + return; // REQUIRE throws, but make the early exit explicit so the dereferences below are + // unreachable to a reader and to the compiler } // TODO: Do we need to check the "count" returned? diff --git a/src/proxy/http/HttpCacheSM.cc b/src/proxy/http/HttpCacheSM.cc index 4ddcc27ddcc..a6fe5e0cf91 100644 --- a/src/proxy/http/HttpCacheSM.cc +++ b/src/proxy/http/HttpCacheSM.cc @@ -440,7 +440,7 @@ HttpCacheSM::open_write(const HttpCacheKey *key, URL *url, HTTPHdr *request, Cac CacheHTTPInfo *info = allow_multiple ? reinterpret_cast(CACHE_ALLOW_MULTIPLE_WRITES) : old_info; Action *action_handle = nullptr; - if (master_sm && master_sm->t_state.cache_info.volume_host_rec) { + if (master_sm->t_state.cache_info.volume_host_rec) { action_handle = cacheProcessor.open_write(this, key, info, pin_in_cache, CACHE_FRAG_TYPE_HTTP, master_sm->t_state.cache_info.volume_host_rec); } else { diff --git a/src/proxy/http/remap/RemapYamlConfig.cc b/src/proxy/http/remap/RemapYamlConfig.cc index 7a441434463..abdbaa3ff14 100644 --- a/src/proxy/http/remap/RemapYamlConfig.cc +++ b/src/proxy/http/remap/RemapYamlConfig.cc @@ -183,10 +183,8 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod return {}; } } - if (ipi) { - rule->src_ip_cnt++; - rule->src_ip_valid = 1; - } + rule->src_ip_cnt++; + rule->src_ip_valid = 1; return {}; }; @@ -239,10 +237,8 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod return {}; } } - if (ipi) { - rule->src_ip_category_cnt++; - rule->src_ip_category_valid = 1; - } + rule->src_ip_category_cnt++; + rule->src_ip_category_valid = 1; return {}; }; @@ -284,10 +280,8 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod return {}; } } - if (ipi) { - rule->in_ip_cnt++; - rule->in_ip_valid = 1; - } + rule->in_ip_cnt++; + rule->in_ip_valid = 1; return {}; };