From e0c96241119a9b43cbabf1170040f2d063d4cfdf Mon Sep 17 00:00:00 2001 From: Davide Madrisan <d.madrisan@proton.me> Date: Thu, 12 Sep 2024 20:18:36 +0200 Subject: [PATCH] fix(library): fix clang "deadcode.DeadStores" warnings cpudesc.c:143:11: warning: Although the value stored to 'chread' is used in the enclosing expression, the value is never actually read from 'chread' [deadcode.DeadStores] 143 | while ((chread = getline (&line, &len, fp)) != -1) | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ reported by the static code analyzer scan-build (clang). Signed-off-by: Davide Madrisan <d.madrisan@proton.me> --- README.md | 5 +++-- lib/cpudesc.c | 3 +-- lib/cpustats.c | 6 ++---- lib/interrupts.c | 3 +-- lib/pressure.c | 3 +-- lib/processes.c | 6 ++---- lib/procparser.c | 3 +-- lib/tcpinfo.c | 3 +-- lib/vminfo.c | 3 +-- 9 files changed, 13 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 64d006e2..bee58fd4 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,10 @@ Example (RHEL5 and RHEL6 and other old distributions): ./configure --with-socketfile=/var/run/multipathd.sock If you want to compile the code with a C compiler different from the system default, -you can set the environment variable CC accordingly. Here's an example: +you can set the environment variable CC accordingly. Here are two examples: CC=clang-17 ./configure --libexecdir=/usr/lib/nagios/plugins + CC=clang-18 ./configure --libexecdir=/usr/lib/nagios/plugins ## Installation @@ -106,7 +107,7 @@ This package is known to compile with: * gcc 4.4 (RHEL6 / CentOS 6), * gcc 4.8 (RHEL7 / CentOS 7), * gcc 3.x, 5.1, 5.3, 6.3, 7-14 (openmamba GNU/Linux, Debian 8+, Fedora 25+), -* clang 3.7, 3.8, 4.9, 5, 6, 7, 8, 10-17 (openmamba GNU/Linux, Fedora 25+), +* clang 3.7, 3.8, 4.9, 5, 6, 7, 8, 10-18 (openmamba GNU/Linux, Fedora 25+), List of the Linux kernels that have been successfully tested: * 2.6.18, 2.6.32, diff --git a/lib/cpudesc.c b/lib/cpudesc.c index 60dbdcde..ec35130f 100644 --- a/lib/cpudesc.c +++ b/lib/cpudesc.c @@ -113,7 +113,6 @@ cpu_desc_read (struct cpu_desc *cpudesc) char *line = NULL; FILE *fp; size_t len = 0; - ssize_t chread; struct utsname utsbuf; if (cpudesc == NULL) @@ -140,7 +139,7 @@ cpu_desc_read (struct cpu_desc *cpudesc) cpudesc->mode |= MODE_32BIT; #endif - while ((chread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { if (linelookup (line, "vendor", &cpudesc->vendor)); else if (linelookup (line, "vendor_id", &cpudesc->vendor)); diff --git a/lib/cpustats.c b/lib/cpustats.c index 4d95584f..fefd2fd6 100644 --- a/lib/cpustats.c +++ b/lib/cpustats.c @@ -59,7 +59,6 @@ cpu_stats_get_time (struct cpu_time * __restrict cputime, unsigned int lines) { FILE *fp; size_t len = 0; - ssize_t chread; char *line = NULL; bool found; const char *procpath = get_path_proc_stat (); @@ -70,7 +69,7 @@ cpu_stats_get_time (struct cpu_time * __restrict cputime, unsigned int lines) memset (cputime, '\0', lines * sizeof (struct cpu_time)); found = false; - while ((chread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { if (!strncmp (line, "cpu ", 4)) { @@ -125,7 +124,6 @@ cpu_stats_get_value_with_pattern (const char *pattern, bool mandatory) { FILE *fp; size_t len = 0; - ssize_t chread; char *line = NULL; bool found; unsigned long long value; @@ -137,7 +135,7 @@ cpu_stats_get_value_with_pattern (const char *pattern, bool mandatory) value = 0; found = false; - while ((chread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { if (!strncmp (line, pattern, strlen (pattern))) { diff --git a/lib/interrupts.c b/lib/interrupts.c index e1c9fbcd..52346a5a 100644 --- a/lib/interrupts.c +++ b/lib/interrupts.c @@ -45,7 +45,6 @@ proc_interrupts_get_nintr_per_cpu (unsigned int *ncpus) FILE *fp; char *p, *end, *line = NULL; size_t len = 0; - ssize_t chread; bool header = true; unsigned int cpu; @@ -56,7 +55,7 @@ proc_interrupts_get_nintr_per_cpu (unsigned int *ncpus) unsigned long value, *vintr = xnmalloc (*ncpus, sizeof (unsigned long)); - while ((chread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { /* skip the first line */ if (header) diff --git a/lib/pressure.c b/lib/pressure.c index 672bb4fc..82487c81 100644 --- a/lib/pressure.c +++ b/lib/pressure.c @@ -60,14 +60,13 @@ proc_psi_parser (struct proc_psi_oneline *psi_stat, FILE *fp; int rc = 0; size_t len = 0, label_len; - ssize_t chread; char *line = NULL; if ((fp = fopen (procpath, "r")) == NULL) plugin_error (STATE_UNKNOWN, errno, "error opening %s", procpath); dbg ("reading file %s\n", procpath); - while ((chread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { dbg ("line: %s", line); label_len = strlen (label); diff --git a/lib/processes.c b/lib/processes.c index 9b2c5104..1b1a9a32 100644 --- a/lib/processes.c +++ b/lib/processes.c @@ -147,9 +147,8 @@ procs_list_node_add (uid_t uid, unsigned long inc, new->username = xstrdup (uid_to_username (uid)); #ifdef RLIMIT_NPROC struct rlimit rlim; - int res; - if ((res = getrlimit (RLIMIT_NPROC, &rlim)) < 0) + if (getrlimit (RLIMIT_NPROC, &rlim) < 0) new->rlimit_nproc_soft = new->rlimit_nproc_hard = RLIM_INFINITY; else { @@ -196,7 +195,6 @@ procs_list_getall (unsigned int flags) for (;;) { struct dirent *dp; - ssize_t chread; errno = 0; if ((dp = readdir (dirp)) == NULL) @@ -221,7 +219,7 @@ procs_list_getall (unsigned int flags) gotname = gotuid = gotthreads = false; threads_nbr = 0; - while ((chread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { /* The "Name:" line contains the name of the command that this process is running */ diff --git a/lib/procparser.c b/lib/procparser.c index 53c39c5b..38ed653d 100644 --- a/lib/procparser.c +++ b/lib/procparser.c @@ -54,7 +54,6 @@ procparser (const char *filename, const proc_table_struct *proc_table, char *line = NULL; FILE *fp; size_t len = 0; - ssize_t chread; #if __SIZEOF_LONG__ == 4 unsigned long long slotll; @@ -63,7 +62,7 @@ procparser (const char *filename, const proc_table_struct *proc_table, if ((fp = fopen (filename, "r")) == NULL) plugin_error (STATE_UNKNOWN, errno, "error: cannot read %s", filename); - while ((chread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { char *head = line; char *tail = strchr (line, separator); diff --git a/lib/tcpinfo.c b/lib/tcpinfo.c index 333e8bfe..7f289362 100644 --- a/lib/tcpinfo.c +++ b/lib/tcpinfo.c @@ -106,7 +106,6 @@ procparser_tcp (const char *procfile, struct proc_tcptable_data *data, FILE *fp; char *line = NULL; size_t len = 0; - ssize_t nread; char local_addr_buf[128], rem_addr_buf[128]; unsigned int slot, num, local_port, rem_port; @@ -125,7 +124,7 @@ procparser_tcp (const char *procfile, struct proc_tcptable_data *data, plugin_error (STATE_UNKNOWN, errno, "error opening %s", procfile); /* sl local_addr:local_port rem_addr:rem_port st ... */ - while ((nread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { if (++lnr == 1) /* Skip the heading line */ { diff --git a/lib/vminfo.c b/lib/vminfo.c index d75867d8..56e8ffaa 100644 --- a/lib/vminfo.c +++ b/lib/vminfo.c @@ -258,8 +258,7 @@ proc_vmem_read (struct proc_vmem *vmem) if ((fp = fopen (PROC_STAT, "r"))) { - ssize_t nread; - while ((nread = getline (&line, &len, fp)) != -1) + while (getline (&line, &len, fp) != -1) { if (2 == sscanf (line, "page %lu %lu", &data->vm_pgpgin, &data->vm_pgpgout))