From 6edab86078b33f6c870215df2fb605b8fb2fab60 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Sat, 21 Mar 2020 10:50:33 +0100 Subject: [PATCH] refactor: clean up some compiler warnings (#152) --- mbus/mbus-protocol-aux.c | 8 +------- test/mbus_parse.c | 3 ++- test/mbus_parse_hex.c | 5 +++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index 8877d62..5ddba9f 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -785,8 +785,6 @@ mbus_register_found_event(mbus_handle * handle, void (*event)(mbus_handle * hand int mbus_fixed_normalize(int medium_unit, long medium_value, char **unit_out, double *value_out, char **quantity_out) { - double exponent = 0.0; - int i; medium_unit = medium_unit & 0x3F; if (unit_out == NULL || value_out == NULL || quantity_out == NULL) @@ -807,7 +805,7 @@ int mbus_fixed_normalize(int medium_unit, long medium_value, char **unit_out, do break; default: - for(i=0; fixed_table[i].vif < 0xfff; ++i) + for(int i=0; fixed_table[i].vif < 0xfff; ++i) { if (fixed_table[i].vif == medium_unit) { @@ -820,7 +818,6 @@ int mbus_fixed_normalize(int medium_unit, long medium_value, char **unit_out, do *unit_out = strdup("Unknown"); *quantity_out = strdup("Unknown"); - exponent = 0.0; *value_out = 0.0; return -1; } @@ -835,7 +832,6 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real, unsigned char vif, vife; struct tm time; int value_out_int; - long value_out_long; long long value_out_long_long; *value_out_real = 0.0; *value_out_str = NULL; @@ -1038,7 +1034,6 @@ int mbus_vif_unit_normalize(int vif, double value, char **unit_out, double *value_out, char **quantity_out) { int i; - double exponent = 1.0; unsigned newVif = vif & 0xF7F; /* clear extension bit */ MBUS_DEBUG("vif_unit_normalize = 0x%03X \n", vif); @@ -1063,7 +1058,6 @@ mbus_vif_unit_normalize(int vif, double value, char **unit_out, double *value_ou MBUS_ERROR("%s: Unknown VIF 0x%03X\n", __PRETTY_FUNCTION__, newVif); *unit_out = strdup("Unknown (VIF=0x%.02X)"); *quantity_out = strdup("Unknown"); - exponent = 0.0; *value_out = 0.0; return -1; } diff --git a/test/mbus_parse.c b/test/mbus_parse.c index 2421d90..4c99da6 100644 --- a/test/mbus_parse.c +++ b/test/mbus_parse.c @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { FILE *fp = NULL; - size_t buff_len, len; + size_t len; int normalized = 0; unsigned char buf[1024]; mbus_frame reply; @@ -53,6 +53,7 @@ main(int argc, char *argv[]) if (ferror(fp) != 0) { fprintf(stderr, "%s: failed to read '%s'\n", argv[0], file); + fclose(fp); return 1; } diff --git a/test/mbus_parse_hex.c b/test/mbus_parse_hex.c index 2cd1ce2..0d6b268 100644 --- a/test/mbus_parse_hex.c +++ b/test/mbus_parse_hex.c @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { FILE *fp = NULL; - size_t buff_len, len; + size_t buff_len; int result, normalized = 0; unsigned char raw_buff[4096], buff[4096]; mbus_frame reply; @@ -48,11 +48,12 @@ main(int argc, char *argv[]) } memset(raw_buff, 0, sizeof(raw_buff)); - len = fread(raw_buff, 1, sizeof(raw_buff), fp); + fread(raw_buff, 1, sizeof(raw_buff), fp); if (ferror(fp) != 0) { fprintf(stderr, "%s: failed to read '%s'\n", argv[0], file); + fclose(fp); return 1; }