cleanup: reduce scope of variables

Various things caught by cppcheck that are non-critical.

Change-Id: I495453c84bc15788b85036a163ee36b0ac601fa1
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/main.cpp b/main.cpp
index e2672e4..d8b1135 100644
--- a/main.cpp
+++ b/main.cpp
@@ -55,7 +55,6 @@
 int main(int argc, char* argv[])
 {
     int rc = 0;
-    int c;
     std::string configPath = "";
 
     while (1)
@@ -68,7 +67,7 @@
         // clang-format on
 
         int option_index = 0;
-        c = getopt_long(argc, argv, "c:", long_options, &option_index);
+        int c = getopt_long(argc, argv, "c:", long_options, &option_index);
 
         if (c == -1)
         {
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp
index ef0df14..c2236c2 100644
--- a/pid/ec/pid.cpp
+++ b/pid/ec/pid.cpp
@@ -44,7 +44,7 @@
 {
     float error;
 
-    float p_term = 0.0f;
+    float p_term;
     float i_term = 0.0f;
     float ff_term = 0.0f;
 
diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp
index 4a94458..b1c923f 100644
--- a/pid/fancontroller.cpp
+++ b/pid/fancontroller.cpp
@@ -41,7 +41,6 @@
 
 float FanController::input_proc(void)
 {
-    float sum = 0;
     double value = 0;
     std::vector<int64_t> values;
     std::vector<int64_t>::iterator result;
@@ -62,7 +61,6 @@
             if (value > 0)
             {
                 values.push_back(value);
-                sum += value;
             }
         }
     }
@@ -76,14 +74,9 @@
     value = 0;
     if (values.size() > 0)
     {
-        /* When this is a configuration option in a later update, this code
-         * will be updated.
-         */
-        // value = sum / _inputs.size();
-
         /* the fan PID algorithm was unstable with average, and seemed to work
          * better with minimum.  I had considered making this choice a variable
-         * in the configuration, and I will.
+         * in the configuration, and it's a nice-to-have..
          */
         result = std::min_element(values.begin(), values.end());
         value = *result;
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 92a332e..d5e2646 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -132,13 +132,15 @@
     static constexpr auto setpointpath = "/etc/thermal.d/set-point";
     try
     {
-        int value;
         std::ifstream ifs;
         ifs.open(setpointpath);
         if (ifs.good())
         {
+            int value;
             ifs >> value;
-            max = value; // expecting RPM set-point, not pwm%
+
+            /* expecting RPM set-point, not pwm% */
+            max = static_cast<float>(value);
         }
     }
     catch (const std::exception& e)
diff --git a/sensors/sensor.hpp b/sensors/sensor.hpp
index 9ff0584..2c287cf 100644
--- a/sensors/sensor.hpp
+++ b/sensors/sensor.hpp
@@ -11,7 +11,8 @@
 class Sensor
 {
   public:
-    Sensor(std::string name, int64_t timeout) : _name(name), _timeout(timeout)
+    Sensor(const std::string& name, int64_t timeout) :
+        _name(name), _timeout(timeout)
     {
     }