[chrony-dev] [PATCH] sourcestats.c: Only assign values when needed for `TRACEON` to address warnings

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


Date: Thu, 3 Oct 2013 14:22:37 +0200

The Clang static analyzer scan-build from Debian clang version 3.4-1
currently issues the following two warnings.

        /usr/share/clang/scan-build/ccc-analyzer -O2 -g  -c sourcestats.c
        sourcestats.c:625:5: warning: Value stored to 'prev' is never read
            prev = *sample;
            ^      ~~~~~~~
        sourcestats.c:640:3: warning: Value stored to 'prev_offset' is never read
          prev_offset = inst->estimated_offset;
          ^             ~~~~~~~~~~~~~~~~~~~~~~
        2 warnings generated.

In both cases, the variables are only read, when `TRACEON` is defined.
So only assign them in that case. The warning is gone now.

The compiler probably got rid of the variables already.
---
Should the declaration of the variables also be included into an if
statement?

 sourcestats.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sourcestats.c b/sourcestats.c
index 8df7740..d6a3b06 100644
--- a/sourcestats.c
+++ b/sourcestats.c
@@ -622,7 +622,9 @@ SST_SlewSamples(SST_Stats inst, struct timeval *when, double dfreq, double doffs
   for (m = -inst->runs_samples; m < inst->n_samples; m++) {
     i = get_runsbuf_index(inst, m);
     sample = &(inst->sample_times[i]);
+#ifdef TRACEON
     prev = *sample;
+#endif
     UTI_AdjustTimeval(sample, when, sample, &delta_time, dfreq, doffset);
     prev_offset = inst->offsets[i];
     inst->offsets[i] += delta_time;
@@ -637,7 +639,9 @@ SST_SlewSamples(SST_Stats inst, struct timeval *when, double dfreq, double doffs
 
   /* Do a half-baked update to the regression estimates */
   prev = inst->offset_time;
+#ifdef TRACEON
   prev_offset = inst->estimated_offset;
+#endif
   prev_freq = inst->estimated_frequency;
   UTI_AdjustTimeval(&(inst->offset_time), when, &(inst->offset_time),
       &delta_time, dfreq, doffset);
-- 
1.8.4.rc3

Attachment: signature.asc
Description: This is a digitally signed message part



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/