From 8786d5b67da47901fa3a7a04ffdd2d60ea1aa1ee Mon Sep 17 00:00:00 2001
From: "Christian W. Zuckschwerdt" <christian@zuckschwerdt.org>
Date: Tue, 12 Mar 2024 19:57:47 +0100
Subject: [PATCH] minor: Cleanup clang analyze warnings (closes #2872)

---
 include/bitbuffer.h           | 22 ++++++---
 src/bitbuffer.c               | 21 ++++----
 src/devices/acurite.c         | 90 ++++++++++++++++-------------------
 src/devices/current_cost.c    |  2 +-
 src/devices/efergy_optical.c  | 24 +++-------
 src/devices/honeywell_cm921.c | 21 ++++----
 src/devices/tpms_abarth124.c  | 18 +++----
 src/output_influx.c           |  1 -
 src/output_rtltcp.c           |  2 +-
 src/rtl_433.c                 | 10 ++--
 10 files changed, 96 insertions(+), 115 deletions(-)

diff --git a/include/bitbuffer.h b/include/bitbuffer.h
index 80b81a0f..d2819061 100644
--- a/include/bitbuffer.h
+++ b/include/bitbuffer.h
@@ -102,24 +102,32 @@ int bitrow_snprint(uint8_t const *bitrow, unsigned bit_len, char *str, unsigned
 void bitbuffer_parse(bitbuffer_t *bits, const char *code);
 
 /// Search the specified row of the bitbuffer, starting from bit 'start', for
-/// the pattern provided. Return the location of the first match, or the end
-/// of the row if no match is found.
+/// the pattern provided.
+///
 /// The pattern starts in the high bit. For example if searching for 011011
 /// the byte pointed to by 'pattern' would be 0xAC. (011011xx).
+///
+/// @return the location of the first match, or the end of the row if no match is found.
 unsigned bitbuffer_search(bitbuffer_t *bitbuffer, unsigned row, unsigned start,
         const uint8_t *pattern, unsigned pattern_bits_len);
 
 /// Manchester decoding from one bitbuffer into another, starting at the
-/// specified row and start bit. Decode at most 'max' data bits (i.e. 2*max)
-/// bits from the input buffer). Return the bit position in the input row
+/// specified row and start bit.
+///
+/// Decode at most 'max' data bits (i.e. 2*max) bits from the input buffer).
+/// Manchester per IEEE 802.3 conventions, i.e. high-low is a 0 bit, low-high is a 1 bit.
+///
+/// @return the bit position in the input row
 /// (i.e. returns start + 2*outbuf->bits_per_row[0]).
-/// per IEEE 802.3 conventions, i.e. high-low is a 0 bit, low-high is a 1 bit.
 unsigned bitbuffer_manchester_decode(bitbuffer_t *inbuf, unsigned row, unsigned start,
         bitbuffer_t *outbuf, unsigned max);
 
 /// Differential Manchester decoding from one bitbuffer into another, starting at the
-/// specified row and start bit. Decode at most 'max' data bits (i.e. 2*max)
-/// bits from the input buffer). Return the bit position in the input row
+/// specified row and start bit.
+///
+/// Decode at most 'max' data bits (i.e. 2*max) bits from the input buffer).
+///
+/// @return the bit position in the input row
 /// (i.e. returns start + 2*outbuf->bits_per_row[0]).
 unsigned bitbuffer_differential_manchester_decode(bitbuffer_t *inbuf, unsigned row, unsigned start,
         bitbuffer_t *outbuf, unsigned max);
diff --git a/src/bitbuffer.c b/src/bitbuffer.c
index 606c210b..ce00bdf1 100644
--- a/src/bitbuffer.c
+++ b/src/bitbuffer.c
@@ -347,23 +347,18 @@ static void print_bitrow(uint8_t const *bitrow, unsigned bit_len, unsigned highe
 
 static void print_bitbuffer(const bitbuffer_t *bits, int always_binary)
 {
-    unsigned highest_indent, indent_this_col, indent_this_row;
-    unsigned col, row;
-
-    /* Figure out the longest row of bit to get the highest_indent
-     */
-    highest_indent = sizeof("[dd] {dd} ") - 1;
-    for (row = indent_this_row = 0; row < bits->num_rows; ++row) {
-        for (col = indent_this_col = 0; col < (unsigned)(bits->bits_per_row[row] + 7) / 8; ++col) {
-            indent_this_col += 2 + 1;
-        }
-        indent_this_row = indent_this_col;
-        if (indent_this_row > highest_indent)
+    // Figure out the longest row of bits to get the highest_indent
+    unsigned highest_indent = sizeof("[dd] {dd} ") - 1;
+    for (unsigned row = 0; row < bits->num_rows; ++row) {
+        unsigned hex_bytes = (bits->bits_per_row[row] + 7) / 8;
+        unsigned indent_this_row = (2 + 1) * hex_bytes;
+        if (indent_this_row > highest_indent) {
             highest_indent = indent_this_row;
+        }
     }
 
     fprintf(stderr, "bitbuffer:: Number of rows: %u \n", bits->num_rows);
-    for (row = 0; row < bits->num_rows; ++row) {
+    for (unsigned row = 0; row < bits->num_rows; ++row) {
         fprintf(stderr, "[%02u] ", row);
         print_bitrow(bits->bb[row], bits->bits_per_row[row], highest_indent, always_binary);
     }
diff --git a/src/devices/acurite.c b/src/devices/acurite.c
index 0aaeee5c..7f271d80 100644
--- a/src/devices/acurite.c
+++ b/src/devices/acurite.c
@@ -141,12 +141,12 @@ static char const *acurite_getChannel(uint8_t byte)
 
 // Add exception and raw message bytes to message to enable
 // later analysis of unexpected/possibly undecoded data
-static void data_append_exception(data_t* data, int exception, uint8_t* bb, int browlen)
+static data_t *data_append_exception(data_t *data, int exception, uint8_t const *bb, int browlen)
 {
     char raw_str[31], *rawp;
 
     rawp = (char *)raw_str;
-    for (int i=0; i < browlen; i++) {
+    for (int i = 0; i < browlen && (size_t)i < sizeof(raw_str) / 2; i++) {
         sprintf(rawp,"%02x",bb[i]);
         rawp += 2;
     }
@@ -159,6 +159,7 @@ static void data_append_exception(data_t* data, int exception, uint8_t* bb, int
             NULL);
     /* clang-format on */
 
+    return data;
 }
 
 
@@ -168,7 +169,7 @@ Acurite 896 rain gauge
 */
 static int acurite_rain_896_decode(r_device *decoder, bitbuffer_t *bitbuffer)
 {
-    uint8_t *b = bitbuffer->bb[0];
+    uint8_t const *b = bitbuffer->bb[0];
     int id;
     float total_rain;
     data_t *data;
@@ -220,7 +221,7 @@ Acurite 609 Temperature and Humidity Sensor.
 */
 static int acurite_th_decode(r_device *decoder, bitbuffer_t *bitbuffer)
 {
-    uint8_t *bb = NULL;
+    uint8_t const *bb = NULL;
     int cksum, battery_low, valid = 0;
     float tempc;
     uint8_t humidity, id, status;
@@ -408,7 +409,7 @@ static int acurite_6045_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsign
     data_t *data;
 
     int browlen = (bitbuffer->bits_per_row[row] + 7) / 8;
-    uint8_t *bb = bitbuffer->bb[row];
+    uint8_t const *bb = bitbuffer->bb[row];
 
     char const *channel_str = acurite_getChannel(bb[0]); // same as TXR
 
@@ -495,7 +496,7 @@ static int acurite_6045_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsign
 Acurite 899 Rain Gauge decoder
 
 */
-static int acurite_899_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t *bb)
+static int acurite_899_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t const *bb)
 {
     (void)bitbuffer;
     // MIC (checksum, parity) validated in calling function
@@ -512,7 +513,7 @@ static int acurite_899_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t
 
     int channel = bb[0] >> 6;
     // @todo replace the above with this:
-    // char const* channel_str = acurite_getChannel(bb[0]);
+    // char const *channel_str = acurite_getChannel(bb[0]);
 
 
     /*
@@ -539,19 +540,18 @@ static int acurite_899_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t
     decoder_output_data(decoder, data);
 
     return 1; // if we got here, 1 message was output
-
 }
 
 /**
 Acurite 3n1 Weather Station decoder
 
 */
-static int acurite_3n1_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t *bb)
+static int acurite_3n1_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t const *bb)
 {
     // MIC (checksum, parity) validated in calling function
     (void)bitbuffer;
 
-    char const* channel_str = acurite_getChannel(bb[0]);
+    char const *channel_str = acurite_getChannel(bb[0]);
 
     // 3n1 sensor ID is 14 bits
     uint16_t sensor_id = ((bb[0] & 0x3f) << 8) | bb[1];
@@ -629,12 +629,12 @@ Acurite 5n1 Weather Station decoder
 XXX todo docs
 
 */
-static int acurite_5n1_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t* bb)
+static int acurite_5n1_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t const *bb)
 {
     // MIC (checksum, parity) validated in calling function
     (void)bitbuffer;
 
-    char const* channel_str = acurite_getChannel(bb[0]);
+    char const *channel_str = acurite_getChannel(bb[0]);
     uint16_t sensor_id = ((bb[0] & 0x0f) << 8) | bb[1];
     uint8_t sequence_num = (bb[0] & 0x30) >> 4;
     int battery_low = (bb[2] & 0x40) == 0;
@@ -790,25 +790,20 @@ Lux needs to multiplied by 10.
 */
 static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row)
 {
-    uint8_t humidity, sequence_num, message_type;
-    char raw_str[31], *rawp;
-    uint16_t sensor_id;
-    int raincounter, battery_low;
     int exception = 0;
-    float tempf, wind_dir, wind_speed_mph;
-    data_t *data;
 
     int browlen = (bitbuffer->bits_per_row[row] + 7) / 8;
-    uint8_t *bb = bitbuffer->bb[row];
+    uint8_t const *bb = bitbuffer->bb[row];
 
-    message_type = bb[2] & 0x3f;
-    sensor_id = ((bb[0] & 0x03) << 8) | bb[1];
+    uint8_t message_type     = bb[2] & 0x3f;
+    uint16_t sensor_id = ((bb[0] & 0x03) << 8) | bb[1];
     char const *channel_str = acurite_getChannel(bb[0]);
 
     // There are still a few unknown/unused bits in the message that
     // message that could possibly hold some data. Add the raw message hex to
     // to the structured data output to allow future analysis without
     // having to enable debug for long running rtl_433 processes.
+    char raw_str[31], *rawp;
     rawp = (char *)raw_str;
     for (int i=0; i < MIN(browlen, 15); i++) {
         sprintf(rawp,"%02x",bb[i]);
@@ -823,13 +818,13 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
     //  xxxx 00 xx = first copy
     //  xxxx 01 xx = second copy
     //  xxxx 10 xx = third copy
-    sequence_num = (bb[0] & 0x0c) >> 2;
+    uint8_t sequence_num = (bb[0] & 0x0c) >> 2;
     // Battery status is the 7th bit 0x40. 1 = normal, 0 = low
-    battery_low = (bb[2] & 0x40) == 0;
+    int battery_low = (bb[2] & 0x40) == 0;
 
     // Wind speed is 8-bits raw MPH
     // Spec is 0-200 MPH
-    wind_speed_mph = ((bb[3] & 0x7F) << 1) | ((bb[4] & 0x40) >> 6);
+    float wind_speed_mph = ((bb[3] & 0x7F) << 1) | ((bb[4] & 0x40) >> 6);
 
     if (wind_speed_mph > 200) {
         decoder_logf(decoder, 1, __func__, "Atlas 0x%04X Ch %s, invalid wind speed: %.1f MPH",
@@ -838,7 +833,7 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
     }
 
     /* clang-format off */
-    data = data_make(
+    data_t *data = data_make(
             "model",                "",             DATA_STRING, "Acurite-Atlas",
             "id",                   NULL,           DATA_INT,    sensor_id,
             "channel",              NULL,           DATA_STRING, channel_str,
@@ -861,7 +856,7 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
         if ((bb[4] & 0x30) != 0)
             exception++;
 
-        tempf = (temp_raw - 400) * 0.1;
+        float tempf = (temp_raw - 400) * 0.1;
         if (tempf < -40.0 || tempf > 158.0) {
             decoder_logf(decoder, 1, __func__, "Atlas 0x%04X Ch %s, invalid temperature: %0.1f F",
                          sensor_id, channel_str, tempf);
@@ -872,7 +867,7 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
         // Fail sanity check over 100% humidity
         // Allow 0 because very low battery or defective sensor will report
         // those values.
-        humidity = (bb[6] & 0x7f);
+        uint8_t humidity = (bb[6] & 0x7f);
         if (humidity > 100) {
             decoder_logf(decoder, 1, __func__, "0x%04X Ch %s : Impossible humidity: %d %%rH",
                          sensor_id, channel_str, humidity);
@@ -901,7 +896,7 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
         // As with temperatuve message, flag msg if those two extra bits
         // are ever non-zero so they can be investigated
         // Note: output as float, but currently can only be decoded an integer
-        wind_dir = ((bb[4] & 0x1f) << 5) | ((bb[5] & 0x7c) >> 2);
+        float wind_dir = ((bb[4] & 0x1f) << 5) | ((bb[5] & 0x7c) >> 2);
         if ((bb[4] & 0x30) != 0)
             exception++;
 
@@ -913,7 +908,7 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
 
         // range: 0 to 5.11 in, 0.01 inch increments, accumulated
         // JRH: Confirmed 9 bits, counter rolls over after 5.11 inches
-        raincounter = ((bb[5] & 0x03) << 7) | (bb[6] & 0x7F);
+        int raincounter = ((bb[5] & 0x03) << 7) | (bb[6] & 0x7F);
 
         /* clang-format off */
         data = data_append(data,
@@ -1005,13 +1000,13 @@ Notes:
   - @todo - check if high 3 bits ever used for anything else
 
 */
-static int acurite_tower_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t *bb)
+static int acurite_tower_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t const *bb)
 {
     // MIC (checksum, parity) validated in calling function
 
     (void)bitbuffer;
     int exception = 0;
-    char const* channel_str = acurite_getChannel(bb[0]);
+    char const *channel_str = acurite_getChannel(bb[0]);
     int sensor_id = ((bb[0] & 0x3f) << 8) | bb[1];
     int battery_low = (bb[2] & 0x40) == 0;
 
@@ -1043,9 +1038,8 @@ static int acurite_tower_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8
     if ((temp_raw & 0x3800) != 0)
         exception++;
 
-    data_t* data;
     /* clang-format off */
-    data = data_make(
+    data_t *data = data_make(
             "model",                "",             DATA_STRING, "Acurite-Tower",
             "id",                   "",             DATA_INT,    sensor_id,
             "channel",              NULL,           DATA_STRING, channel_str,
@@ -1056,8 +1050,9 @@ static int acurite_tower_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8
             NULL);
     /* clang-format on */
 
-    if (exception)
-        data_append_exception(data, exception, bb, ACURITE_TXR_BYTELEN);
+    if (exception) {
+        data = data_append_exception(data, exception, bb, ACURITE_TXR_BYTELEN);
+    }
 
     decoder_output_data(decoder, data);
 
@@ -1072,12 +1067,12 @@ related information from their website so specs, manual, etc.
 aren't easy to find
 
 */
-static int acurite_1190_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t *bb)
+static int acurite_1190_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t const *bb)
 {
     (void)bitbuffer;
     // Channel is the first two bits of the 0th byte
     // but only 3 of the 4 possible values are valid
-    char const* channel_str = acurite_getChannel(bb[0]);
+    char const *channel_str = acurite_getChannel(bb[0]);
 
     // Tower sensor ID is the last 14 bits of byte 0 and 1
     // CCII IIII | IIII IIII
@@ -1089,9 +1084,8 @@ static int acurite_1190_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_
     // Leak indicator bit is the 5th bit of byte 3. 1 = wet, 0 = dry
     int is_wet = (bb[3] & 0x10) >> 4;
 
-    data_t* data;
     /* clang-format off */
-    data = data_make(
+    data_t *data = data_make(
             "model",                "",             DATA_STRING, "Acurite-Leak",
             "id",                   "",             DATA_INT,    sensor_id,
             "channel",              NULL,           DATA_STRING, channel_str,
@@ -1121,7 +1115,7 @@ CCII IIII | IIII IIII | pBMM MMMM | bTTT TTTT | bTTT TTTT | KKKK KKKK
 - p: Parity bit
 
 */
-static int acurite_515_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t *bb)
+static int acurite_515_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t const *bb)
 {
     // length, MIC (checksum, parity) validated in calling function
 
@@ -1131,7 +1125,7 @@ static int acurite_515_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t
     uint8_t message_type = bb[2] & 0x3f;
 
     // Channel A, B, C, common with other Acurite devices
-    char const* channel_str = acurite_getChannel(bb[0]);
+    char const *channel_str = acurite_getChannel(bb[0]);
 
     channel_type_str[0] = channel_str[0];
 
@@ -1173,9 +1167,8 @@ static int acurite_515_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t
     // Battery status is the 7th bit 0x40. 1 = normal, 0 = low
     int battery_low = (bb[2] & 0x40) == 0;
 
-    data_t* data;
     /* clang-format off */
-    data = data_make(
+    data_t *data = data_make(
         "model",                "",             DATA_STRING, "Acurite-515",
         "id",                   "",             DATA_INT,    sensor_id,
         "channel",              NULL,           DATA_STRING, channel_type_str,
@@ -1185,8 +1178,9 @@ static int acurite_515_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t
         NULL);
     /* clang-format on */
 
-    if (exception)
-        data_append_exception(data, exception, bb, ACURITE_515_BYTELEN);
+    if (exception) {
+        data = data_append_exception(data, exception, bb, ACURITE_515_BYTELEN);
+    }
 
     decoder_output_data(decoder, data);
 
@@ -1371,7 +1365,7 @@ static int acurite_txr_decode(r_device *decoder, bitbuffer_t *bitbuffer)
             if ((ret = acurite_txr_check(decoder, bb, browlen, ACURITE_1190_BYTELEN)) != 0) {
                 error_ret = ret;
             } else {
-                    if ((ret = acurite_1190_decode(decoder, bitbuffer, bb)) > 0) {
+                if ((ret = acurite_1190_decode(decoder, bitbuffer, bb)) > 0) {
                     decoded += ret;
                 } else if (ret < 0) {
                     error_ret = ret;
@@ -1548,7 +1542,7 @@ bit issue gets resolved.
 static int acurite_986_decode(r_device *decoder, bitbuffer_t *bitbuffer)
 {
     int const browlen = 5;
-    uint8_t *bb, sensor_num, status, crc, crcc;
+    uint8_t sensor_num, status, crc, crcc;
     uint8_t br[8];
     int8_t tempf; // Raw Temp is 8 bit signed Fahrenheit
     uint16_t sensor_id, valid_cnt = 0;
@@ -1569,7 +1563,7 @@ static int acurite_986_decode(r_device *decoder, bitbuffer_t *bitbuffer)
             result = DECODE_ABORT_LENGTH;
             continue; // DECODE_ABORT_LENGTH
         }
-        bb = bitbuffer->bb[brow];
+        uint8_t const *bb = bitbuffer->bb[brow];
 
         // Reduce false positives
         // may eliminate these with a better PPM (precise?) demod.
diff --git a/src/devices/current_cost.c b/src/devices/current_cost.c
index f96caaa3..42d91d70 100644
--- a/src/devices/current_cost.c
+++ b/src/devices/current_cost.c
@@ -55,7 +55,7 @@ static int current_cost_decode(r_device *decoder, bitbuffer_t *bitbuffer)
         start_pos += 45;
     }
 
-    start_pos = bitbuffer_manchester_decode(bitbuffer, 0, start_pos, &packet, 0);
+    bitbuffer_manchester_decode(bitbuffer, 0, start_pos, &packet, 0);
 
     if (packet.bits_per_row[0] < 64) {
         return DECODE_ABORT_EARLY;
diff --git a/src/devices/efergy_optical.c b/src/devices/efergy_optical.c
index df21a2f6..54b621c8 100644
--- a/src/devices/efergy_optical.c
+++ b/src/devices/efergy_optical.c
@@ -38,12 +38,6 @@ static int efergy_optical_callback(r_device *decoder, bitbuffer_t *bitbuffer)
 {
     unsigned num_bits = bitbuffer->bits_per_row[0];
     uint8_t *bytes = bitbuffer->bb[0];
-    float energy, n_imp;
-    int pulsecount;
-    float seconds;
-    data_t *data;
-    uint16_t crc;
-    uint16_t csum1;
 
     if (num_bits < 96 || num_bits > 100)
         return DECODE_ABORT_LENGTH;
@@ -80,9 +74,9 @@ static int efergy_optical_callback(r_device *decoder, bitbuffer_t *bitbuffer)
     // crc16 xmodem with start value of 0x00 and polynomic of 0x1021 is same as CRC-CCITT (0x0000)
     // start of data, length of data=10, polynomic=0x1021, init=0x0000
 
-    csum1 = (bytes[10] << 8) | (bytes[11]);
+    uint16_t csum1 = (bytes[10] << 8) | (bytes[11]);
 
-    crc = crc16(bytes, 10, 0x1021, 0x0000);
+    uint16_t crc = crc16(bytes, 10, 0x1021, 0x0000);
 
     if (crc != csum1) {
         decoder_log(decoder, 1, __func__, "CRC error.");
@@ -91,26 +85,22 @@ static int efergy_optical_callback(r_device *decoder, bitbuffer_t *bitbuffer)
 
     unsigned id = ((unsigned)bytes[0] << 16) | (bytes[1] << 8) | (bytes[2]);
 
-    // this setting depends on your electricity meter's optical output
-    n_imp = 3200;
-
     // interval:
     // - red led (every 30s):    bytes[3]=64 (0100 0000)
     // - orange led (every 60s): bytes[3]=80 (0101 0000)
     // - green led (every 90s):  bytes[3]=96 (0110 0000)
-    seconds = (((bytes[3] & 0x30) >> 4) + 1) * 30.0;
+    float seconds = (((bytes[3] & 0x30) >> 4) + 1) * 30.0;
 
-    pulsecount = bytes[8];
-
-    energy = (((float)pulsecount / n_imp) * (3600 / seconds));
+    int pulsecount = bytes[8];
 
+    // this setting depends on your electricity meter's optical output
     // New code for calculating various energy values for differing pulse-kwh values
     const int imp_kwh[] = {4000, 3200, 2000, 1000, 500, 0};
     for (unsigned i = 0; imp_kwh[i] != 0; ++i) {
-        energy = (((float)pulsecount / imp_kwh[i]) * (3600 / seconds));
+        float energy = (((float)pulsecount / imp_kwh[i]) * (3600 / seconds));
 
         /* clang-format off */
-        data = data_make(
+        data_t *data = data_make(
                 "model",        "Model",        DATA_STRING, "Efergy-Optical",
                 "id",           "",             DATA_INT,   id,
                 "pulses",       "Pulse-rate",   DATA_INT, imp_kwh[i],
diff --git a/src/devices/honeywell_cm921.c b/src/devices/honeywell_cm921.c
index 4adf02c5..b0af5e97 100644
--- a/src/devices/honeywell_cm921.c
+++ b/src/devices/honeywell_cm921.c
@@ -134,7 +134,6 @@ static data_t *honeywell_cm921_interpret_message(r_device *decoder, const messag
 
     data = decode_device_ids(msg, data, 1);
 
-    data_t *r = data;
     switch (msg->command) {
         case 0x1030: {
             UNKNOWN_IF(msg->payload_length != 16);
@@ -161,15 +160,15 @@ static data_t *honeywell_cm921_interpret_message(r_device *decoder, const messag
                 case 1:
                     data = data_append(data, "time_request", "", DATA_INT, msg->payload[0], NULL); break;
                 case 9: {
-                    //uint8_t unknown_0 = msg->payload[0]; /* always == 0? */
-                    //uint8_t unknown_1 = msg->payload[1]; /* direction? */
-                    uint8_t second = msg->payload[2];
-                    uint8_t minute = msg->payload[3];
-                    //uint8_t day_of_week = msg->payload[4] >> 5;
-                    uint8_t hour = msg->payload[4] & 0x1F;
-                    uint8_t day = msg->payload[5];
-                    uint8_t month = msg->payload[6];
-                    uint8_t year[2] = { msg->payload[7],  msg->payload[8] };
+                    //uint8_t const unknown_0 = msg->payload[0]; /* always == 0? */
+                    //uint8_t const unknown_1 = msg->payload[1]; /* direction? */
+                    uint8_t const second = msg->payload[2];
+                    uint8_t const minute = msg->payload[3];
+                    //uint8_t const day_of_week = msg->payload[4] >> 5;
+                    uint8_t const hour = msg->payload[4] & 0x1F;
+                    uint8_t const day = msg->payload[5];
+                    uint8_t const month = msg->payload[6];
+                    uint8_t const year[2] = { msg->payload[7],  msg->payload[8] };
                     char time_str[256];
                     snprintf(time_str, sizeof(time_str), "%02d:%02d:%02d %02d-%02d-%04d", hour, minute, second, day, month, (year[0] << 8) | year[1]);
                     data = data_append(data, "datetime", "", DATA_STRING, time_str, NULL);
@@ -254,7 +253,7 @@ static data_t *honeywell_cm921_interpret_message(r_device *decoder, const messag
         default: /* Unknown command */
             UNKNOWN_IF(1);
     }
-    return r;
+    return data;
 }
 
 static uint8_t next(const uint8_t *bb, unsigned *ipos, unsigned num_bytes)
diff --git a/src/devices/tpms_abarth124.c b/src/devices/tpms_abarth124.c
index 26c1129c..9a89742d 100644
--- a/src/devices/tpms_abarth124.c
+++ b/src/devices/tpms_abarth124.c
@@ -39,12 +39,6 @@ Data layout (nibbles):
 static int tpms_abarth124_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, unsigned bitpos)
 {
     bitbuffer_t packet_bits = {0};
-    uint8_t *b;
-    int pressure;
-    int temperature;
-    int status;
-    int checksum;
-
     bitbuffer_manchester_decode(bitbuffer, row, bitpos, &packet_bits, 72);
 
     // make sure we decoded the expected number of bits
@@ -53,18 +47,18 @@ static int tpms_abarth124_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsi
         return 0; // DECODE_FAIL_SANITY;
     }
 
-    b = packet_bits.bb[0];
+    uint8_t *b = packet_bits.bb[0];
 
     // check checksum (checksum8 xor)
-    checksum = xor_bytes(b, 9);
+    int const checksum = xor_bytes(b, 9);
     if (checksum != 0) {
         return 0; // DECODE_FAIL_MIC;
     }
 
-    pressure    = b[5];
-    temperature = b[6];
-    status      = b[7];
-    checksum    = b[8];
+    int const pressure    = b[5];
+    int const temperature = b[6];
+    int const status      = b[7];
+    // int const checksum    = b[8];
 
     char flags[1 * 2 + 1];
     snprintf(flags, sizeof(flags), "%02x", b[4]);
diff --git a/src/output_influx.c b/src/output_influx.c
index 3eaf9637..735438e3 100644
--- a/src/output_influx.c
+++ b/src/output_influx.c
@@ -371,7 +371,6 @@ static void R_API_CALLCONV print_influx_data(data_output_t *output, data_t *data
                 str++;
             end = &buf->buf[buf->len - 1];
             influx_sanitize_tag(str, end);
-            str = end + 1;
             print_value(output, data->type, data->value, data->format);
             comma = true;
         }
diff --git a/src/output_rtltcp.c b/src/output_rtltcp.c
index 2ec4a373..aec6581c 100644
--- a/src/output_rtltcp.c
+++ b/src/output_rtltcp.c
@@ -168,7 +168,7 @@ static int parse_command(r_cfg_t *cfg, int control, uint8_t const *buf, int len)
     int cmd = buf[0];
     unsigned arg = (unsigned)buf[1] << 24 | buf[2] << 16 | buf[3] << 8 | buf[4];
     // print_logf(LOG_TRACE, "rtl_tcp", "CMD: %d with %u (%d) %02x %02x %02x %02x", cmd, arg, (int)arg, buf[1], buf[2], buf[3], buf[4]);
-    len -= 5;
+    // len -= 5;
 
     switch (cmd) {
     case RTLTCP_SET_FREQ:
diff --git a/src/rtl_433.c b/src/rtl_433.c
index c66f427b..2f059ad6 100644
--- a/src/rtl_433.c
+++ b/src/rtl_433.c
@@ -1895,8 +1895,9 @@ int main(int argc, char **argv) {
                     }
                 }
 
-                if (in_file != stdin)
-                    fclose(in_file = stdin);
+                if (in_file != stdin) {
+                    fclose(in_file);
+                }
 
                 continue;
             }
@@ -1964,8 +1965,9 @@ int main(int argc, char **argv) {
                 print_logf(LOG_NOTICE, "Input", "Test mode file issued %d packets", n_blocks);
             }
 
-            if (in_file != stdin)
-                fclose(in_file = stdin);
+            if (in_file != stdin) {
+                fclose(in_file);
+            }
         }
 
         close_dumpers(cfg);