Skip to content

Add assert of CacheDisk is not nullptr - #10704

Merged
masaori335 merged 1 commit into
apache:masterfrom
masaori335:fix-odd-clang-analyzer
Nov 1, 2023
Merged

masaori335 merged 1 commit into
apache:masterfrom
masaori335:fix-odd-clang-analyzer

Conversation

@masaori335

Copy link
Copy Markdown
Contributor

To make clang-analyer happy.

We faced odd warning report with clang-analyer at #10694.

analyze-build: INFO: /Users/masaori/src/github.com/apache/trafficserver-asf-master/src/iocore/cache/Cache.cc:1271:20: warning: Access to field 'disk_vols' results in a dereference of a null pointer (loaded from variable 'd') [core.NullDereference]
analyze-build: INFO:  1271 |     DiskVol **dp = d->disk_vols;

If I run clang-analyer against the master branch with below change locally, it also reports the same. My guess is the Metircs related change made clang-analyzer confused.

diff --git a/src/iocore/cache/Cache.cc b/src/iocore/cache/Cache.cc
index 2679611f9..95e878f66 100644
--- a/src/iocore/cache/Cache.cc
+++ b/src/iocore/cache/Cache.cc
@@ -511,9 +511,9 @@ CacheProcessor::diskInitialized()

   /* Practically just took all bad_disks offline so update the stats. */
   // ToDo: These don't get update on the per-volume metrics :-/
-  Metrics::write(cache_rsb.span_offline, bad_disks);
-  Metrics::decrement(cache_rsb.span_failing, bad_disks);
-  Metrics::write(cache_rsb.span_online, gndisks);
+  // Metrics::write(cache_rsb.span_offline, bad_disks);
+  // Metrics::decrement(cache_rsb.span_failing, bad_disks);
+  // Metrics::write(cache_rsb.span_online, gndisks);

   /* create the cachevol list only if num volumes are greater than 0. */
   if (config_volumes.num_volumes == 0) {

As @ywkaras suggested in the PR, the warning is gone with this assert.

/cc @zwoop

@masaori335 masaori335 added this to the 10.0.0 milestone Oct 31, 2023
@masaori335
masaori335 requested a review from ywkaras October 31, 2023 23:58
@masaori335 masaori335 self-assigned this Oct 31, 2023
zwoop
zwoop previously approved these changes Nov 1, 2023
@masaori335
masaori335 force-pushed the fix-odd-clang-analyzer branch from 1a965c9 to ec82096 Compare November 1, 2023 01:49
@masaori335
masaori335 merged commit 5088bba into apache:master Nov 1, 2023
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.

3 participants