From 629fa81b5760a03520bc4914731e93b0d9f7c487 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 13 May 2017 00:01:00 -0500 Subject: [PATCH] misc: eliminate all those remaining gcc -Wall warnings Reference(s): proc/readproc.c: In function 'statm2proc' proc/readproc.c:627:9: warning: variable 'num' set but not used [-Wunused-but-set-variable] ps/output.c: In function 'pr_context': ps/output.c:1273:14: warning: unused variable 'tried_load' [-Wunused-variable] ps/output.c:1272:16: warning: unused variable 'ps_is_selinux_enabled' [-Wunused-variable] ps/output.c:1272:16: warning: 'ps_is_selinux_enabled' defined but not used [-Wunused-variable] ps/output.c:1273:14: warning: 'tried_load' defined but not used [-Wunused-variable] ps/output.c:1837:18: warning: 'shortsort_array_count' defined but not used [-Wunused-const-variable=] ps/output.c:1803:18: warning: 'aix_array_count' defined but not used [-Wunused-const-variable=] ps/parser.c: In function 'arg_type': ps/parser.c:1098:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation] ps/parser.c:1099:34: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if' ps/sortformat.c: In function 'format_parse': ps/sortformat.c:241:1: warning: label 'out' defined but not used [-Wunused-label] ps/stacktrace.c:176:13: warning: 'stack_trace_sigsegv' defined but not used [-Wunused-function] watch.c: In function 'process_ansi': watch.c:234:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation] watch.c:237:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if' Signed-off-by: Jim Warner --- free.c | 1 - proc/readproc.c | 4 +--- ps/output.c | 11 ++++++----- ps/parser.c | 2 +- ps/sortformat.c | 2 +- ps/stacktrace.c | 2 ++ watch.c | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/free.c b/free.c index 3db0b59e..91fa4c71 100644 --- a/free.c +++ b/free.c @@ -202,7 +202,6 @@ static void check_unit_set(int *unit_set) int main(int argc, char **argv) { int c, flags = 0, unit_set = 0; - char *endptr; struct commandline_arguments args; /* diff --git a/proc/readproc.c b/proc/readproc.c index 48b56f67..0a30edee 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -624,11 +624,9 @@ LEAVE(0x160); ///////////////////////////////////////////////////////////////////////// static void statm2proc(const char* s, proc_t *restrict P) { - int num; - num = sscanf(s, "%ld %ld %ld %ld %ld %ld %ld", + sscanf(s, "%ld %ld %ld %ld %ld %ld %ld", &P->size, &P->resident, &P->share, &P->trs, &P->lrs, &P->drs, &P->dt); -/* fprintf(stderr, "statm2proc converted %d fields.\n",num); */ } static int file2str(const char *directory, const char *what, struct utlbuf_s *ub) { diff --git a/ps/output.c b/ps/output.c index 8c6a5289..f9a29bf6 100644 --- a/ps/output.c +++ b/ps/output.c @@ -1262,13 +1262,14 @@ static int pr_lxcname(char *restrict const outbuf, const proc_t *restrict const static int pr_context(char *restrict const outbuf, const proc_t *restrict const pp){ static void (*ps_freecon)(char*) = 0; static int (*ps_getpidcon)(pid_t pid, char **context) = 0; - static int (*ps_is_selinux_enabled)(void) = 0; - static int tried_load = 0; - static int selinux_enabled = 0; + static int selinux_enabled = 0;; size_t len; char *context; #if ENABLE_LIBSELINUX + static int (*ps_is_selinux_enabled)(void) = 0; + static int tried_load = 0; + if(!ps_getpidcon && !tried_load){ void *handle = dlopen("libselinux.so.1", RTLD_NOW); if(handle){ @@ -1792,7 +1793,7 @@ static const aix_struct aix_array[] = { {'z', "vsz", "VSZ"}, {'~', "~", "~"} /* NULL would ruin alphabetical order */ }; -static const int aix_array_count = sizeof(aix_array)/sizeof(aix_struct); +//static const int aix_array_count = sizeof(aix_array)/sizeof(aix_struct); /********************* sorting ***************************/ @@ -1826,7 +1827,7 @@ static const shortsort_struct shortsort_array[] = { {'y', "priority" }, /* nice */ {'~', "~" } /* NULL would ruin alphabetical order */ }; -static const int shortsort_array_count = sizeof(shortsort_array)/sizeof(shortsort_struct); +//static const int shortsort_array_count = sizeof(shortsort_array)/sizeof(shortsort_struct); /*********** print format_array **********/ diff --git a/ps/parser.c b/ps/parser.c index 8d533b38..4287d074 100644 --- a/ps/parser.c +++ b/ps/parser.c @@ -1096,7 +1096,7 @@ static int arg_type(const char *str){ if((tmp>='a') && (tmp<='z')) return ARG_GNU; if((tmp>='A') && (tmp<='Z')) return ARG_GNU; if(tmp=='\0') return ARG_END; - return ARG_FAIL; + return ARG_FAIL; } /* First assume sysv, because that is the POSIX and Unix98 standard. */ diff --git a/ps/sortformat.c b/ps/sortformat.c index 5ffc25b2..ace5fa70 100644 --- a/ps/sortformat.c +++ b/ps/sortformat.c @@ -238,7 +238,7 @@ static const char *format_parse(sf_node *sfn){ need_item=0; } } while (*++walk); -out: + if(!items){ free(buf); goto empty; diff --git a/ps/stacktrace.c b/ps/stacktrace.c index a0b4755c..01ea217d 100644 --- a/ps/stacktrace.c +++ b/ps/stacktrace.c @@ -173,10 +173,12 @@ void debug(int method, char *prog_name){ } /************/ +#if 0 static void stack_trace_sigsegv(int signum){ (void)signum; debug(STACK_TRACE, stored_prog_name); } +#endif /************/ #ifdef DEBUG diff --git a/watch.c b/watch.c index 215b4bf5..e8bfb75f 100644 --- a/watch.c +++ b/watch.c @@ -234,8 +234,8 @@ static void process_ansi(FILE * fp) if (buf[0] == '\0') set_ansi_attribute(0); - for (endptr = numstart = buf; *endptr != '\0'; numstart = endptr + 1) { - if (!set_ansi_attribute(strtol(numstart, &endptr, 10))) + for (endptr = numstart = buf; *endptr != '\0'; numstart = endptr + 1) { + if (!set_ansi_attribute(strtol(numstart, &endptr, 10))) break; } }