Skip to content

Commit

Permalink
fix(library): fix clang "deadcode.DeadStores" warnings
Browse files Browse the repository at this point in the history
    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 <[email protected]>
  • Loading branch information
madrisan committed Sep 12, 2024
1 parent 961ce67 commit e0c9624
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions lib/cpudesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
Expand Down
6 changes: 2 additions & 4 deletions lib/cpustats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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))
{
Expand Down Expand Up @@ -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;
Expand All @@ -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)))
{
Expand Down
3 changes: 1 addition & 2 deletions lib/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions lib/pressure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions lib/processes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -196,7 +195,6 @@ procs_list_getall (unsigned int flags)
for (;;)
{
struct dirent *dp;
ssize_t chread;
errno = 0;

if ((dp = readdir (dirp)) == NULL)
Expand All @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions lib/procparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions lib/tcpinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
{
Expand Down
3 changes: 1 addition & 2 deletions lib/vminfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit e0c9624

Please sign in to comment.