Fix various warnings

- unused variable ‘walk’ [-Wunused-variable]
- implicit declaration of built-in function ‘free’
[-Wimplicit-function-declaration]
- initialization discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
- variable 'ram_used' is used uninitialized whenever 'if' condition is
false [-Wsometimes-uninitialized]. This is actually easily reproducible
by specifying `memory_used_method = "XXX"`.
- comparison of integers of different signs: 'int' and 'unsigned long'
[-Wsign-compare] (for `exponent`)
This commit is contained in:
Orestis Floros 2020-05-01 00:36:38 +02:00
parent 57218e98de
commit a68524ee4a
No known key found for this signature in database
GPG Key ID: A09DBD7D3222C1C3
3 changed files with 6 additions and 4 deletions

View File

@ -206,9 +206,9 @@ char *trim(const char *s);
/* src/format_placeholders.c */ /* src/format_placeholders.c */
typedef struct { typedef struct {
/* The placeholder to be replaced, e.g., "%title". */ /* The placeholder to be replaced, e.g., "%title". */
char *name; const char *name;
/* The value this placeholder should be replaced with. */ /* The value this placeholder should be replaced with. */
char *value; const char *value;
} placeholder_t; } placeholder_t;
char *format_placeholders(const char *format, placeholder_t *placeholders, int num); char *format_placeholders(const char *format, placeholder_t *placeholders, int num);

View File

@ -23,7 +23,7 @@ static const char *const iec_symbols[] = {"B", "KiB", "MiB", "GiB", "TiB"};
*/ */
static int print_bytes_human(char *outwalk, unsigned long bytes, const char *unit, const int decimals) { static int print_bytes_human(char *outwalk, unsigned long bytes, const char *unit, const int decimals) {
double base = bytes; double base = bytes;
int exponent = 0; size_t exponent = 0;
while (base >= BINARY_BASE && exponent < MAX_EXPONENT) { while (base >= BINARY_BASE && exponent < MAX_EXPONENT) {
if (strcasecmp(unit, iec_symbols[exponent]) == 0) { if (strcasecmp(unit, iec_symbols[exponent]) == 0) {
break; break;
@ -86,7 +86,6 @@ void print_memory(yajl_gen json_gen, char *buffer, const char *format, const cha
#if defined(linux) #if defined(linux)
const char *selected_format = format; const char *selected_format = format;
const char *walk;
const char *output_color = NULL; const char *output_color = NULL;
int unread_fields = 6; int unread_fields = 6;
@ -140,6 +139,8 @@ void print_memory(yajl_gen json_gen, char *buffer, const char *format, const cha
ram_used = ram_total - ram_available; ram_used = ram_total - ram_available;
} else if (BEGINS_WITH(memory_used_method, "classical")) { } else if (BEGINS_WITH(memory_used_method, "classical")) {
ram_used = ram_total - ram_free - ram_buffers - ram_cached; ram_used = ram_total - ram_free - ram_buffers - ram_cached;
} else {
die("Unexpected value: memory_used_method = %s", memory_used_method);
} }
if (threshold_degraded) { if (threshold_degraded) {

View File

@ -1,6 +1,7 @@
// vim:ts=4:sw=4:expandtab // vim:ts=4:sw=4:expandtab
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <yajl/yajl_gen.h> #include <yajl/yajl_gen.h>
#include <yajl/yajl_version.h> #include <yajl/yajl_version.h>