[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
avoiding 'dead store's reported by clang
From: |
Jim Meyering |
Subject: |
avoiding 'dead store's reported by clang |
Date: |
Tue, 01 Sep 2009 11:50:17 +0200 |
I've run clang on coreutils, and it spotted quite a few dead stores.
These changes remove them:
The chmod.c change below was not completely transparent, since
the new code returns immediately after issuing the root-dev-inode
warning, whereas the old code would fall through, and thus might
have also printed --verbose diagnostics.
Other than that, these are supposed to be "no semantic change" patches.
>From d9cc6dd8b3408b02a7fda0330ec65ef7e0dcddf1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 31 Aug 2009 16:37:36 +0200
Subject: [PATCH 1/6] maint: mbsalign.c: remove unnecessary assignment
* gl/lib/mbsalign.c (mbsalign): Remove assignment, the result of which
is never used.
---
gl/lib/mbsalign.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gl/lib/mbsalign.c b/gl/lib/mbsalign.c
index 0dfda75..a075747 100644
--- a/gl/lib/mbsalign.c
+++ b/gl/lib/mbsalign.c
@@ -219,7 +219,7 @@ mbsalign (const char *src, char *dest, size_t dest_size,
dest = mbs_align_pad (dest, dest_end, start_spaces);
dest = mempcpy(dest, str_to_print, MIN (n_used_bytes, dest_end - dest));
- dest = mbs_align_pad (dest, dest_end, end_spaces);
+ mbs_align_pad (dest, dest_end, end_spaces);
}
mbsalign_cleanup:
--
1.6.4.2.384.g5fc62
>From f480e4a12bf6d82c4e8491cdd82195deaee3652e Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 31 Aug 2009 17:01:26 +0200
Subject: [PATCH 2/6] maint: tail: remove unnecessary initialization
* src/tail.c (tail_bytes): Don't compute "diff" twice.
---
src/tail.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/tail.c b/src/tail.c
index ceda5b6..f0dbf5d 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1437,7 +1437,7 @@ tail_bytes (const char *pretty_filename, int fd,
uintmax_t n_bytes,
off_t diff = end_pos - current_pos;
/* Be careful here. The current position may actually be
beyond the end of the file. */
- off_t bytes_remaining = (diff = end_pos - current_pos) < 0 ? 0 :
diff;
+ off_t bytes_remaining = diff < 0 ? 0 : diff;
off_t nb = n_bytes;
if (bytes_remaining <= nb)
--
1.6.4.2.384.g5fc62
>From 563d50611b99e7f9ef0042f33c95a53299bec261 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 31 Aug 2009 17:05:46 +0200
Subject: [PATCH 3/6] maint: dd: remove unnecessary initialization
* src/dd.c (skip): Remove set-but-never-used variable, soffset.
---
src/dd.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/dd.c b/src/dd.c
index d2f566e..04665f9 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1315,14 +1315,13 @@ skip (int fdesc, char const *file, uintmax_t records,
size_t blocksize,
else
{
int lseek_errno = errno;
- off_t soffset;
/* The seek request may have failed above if it was too big
(> device size, > max file size, etc.)
Or it may not have been done at all (> OFF_T_MAX).
Therefore try to seek to the end of the file,
to avoid redundant reading. */
- if ((soffset = skip_via_lseek (file, fdesc, 0, SEEK_END)) >= 0)
+ if ((skip_via_lseek (file, fdesc, 0, SEEK_END)) >= 0)
{
/* File is seekable, and we're at the end of it, and
size <= OFF_T_MAX. So there's no point using read to advance. */
--
1.6.4.2.384.g5fc62
>From 1af1e3c7c7c74d19b13fb94150541f8489762bcd Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 31 Aug 2009 17:58:53 +0200
Subject: [PATCH 4/6] maint: shred: remove unnecessary initialization
* src/shred.c (genpattern): Value stored to "n" is never used.
---
src/shred.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/shred.c b/src/shred.c
index 43b6d64..2f31789 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -677,7 +677,6 @@ genpattern (int *dest, size_t num, struct randint_source *s)
if ((size_t) k >= n)
{
randpasses += n;
- n = 0;
break;
}
randpasses += k;
--
1.6.4.2.384.g5fc62
>From bf1fc7acdbb5885c8249d4d7cb420812d5d2a37e Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 31 Aug 2009 18:26:16 +0200
Subject: [PATCH 5/6] maint: chown, chgrp, chmod, chcon: remove unnecessary
initialization
* src/chown-core.c: Include "ignore-value.h".
(change_file_owner): Don't set "ent" only to ignore it.
* src/chcon.c (process_file): Likewise.
* src/chmod.c: Include "ignore-value.h".
(process_file): Don't set "ent" only to ignore it.
After diagnosing root-dev/ino failure, return false immediately:
Now that we don't set "ent" we must be sure not to use it uninitialized,
and there's no point in issuing --verbose-related output in this case.
---
src/chcon.c | 3 ++-
src/chmod.c | 5 +++--
src/chown-core.c | 3 ++-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/chcon.c b/src/chcon.c
index 2662600..531ed7a 100644
--- a/src/chcon.c
+++ b/src/chcon.c
@@ -22,6 +22,7 @@
#include "system.h"
#include "dev-ino.h"
#include "error.h"
+#include "ignore-value.h"
#include "quote.h"
#include "quotearg.h"
#include "root-dev-ino.h"
@@ -225,7 +226,7 @@ process_file (FTS *fts, FTSENT *ent)
/* Tell fts not to traverse into this hierarchy. */
fts_set (fts, ent, FTS_SKIP);
/* Ensure that we do not process "/" on the second visit. */
- ent = fts_read (fts);
+ ignore_ptr (fts_read (fts));
return false;
}
return true;
diff --git a/src/chmod.c b/src/chmod.c
index 0e39c8b..aeefcc6 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -25,6 +25,7 @@
#include "dev-ino.h"
#include "error.h"
#include "filemode.h"
+#include "ignore-value.h"
#include "modechange.h"
#include "quote.h"
#include "quotearg.h"
@@ -238,8 +239,8 @@ process_file (FTS *fts, FTSENT *ent)
/* Tell fts not to traverse into this hierarchy. */
fts_set (fts, ent, FTS_SKIP);
/* Ensure that we do not process "/" on the second visit. */
- ent = fts_read (fts);
- ok = false;
+ ignore_ptr (fts_read (fts));
+ return false;
}
if (ok)
diff --git a/src/chown-core.c b/src/chown-core.c
index 7e5774e..eb34904 100644
--- a/src/chown-core.c
+++ b/src/chown-core.c
@@ -25,6 +25,7 @@
#include "system.h"
#include "chown-core.h"
#include "error.h"
+#include "ignore-value.h"
#include "quote.h"
#include "root-dev-ino.h"
#include "xfts.h"
@@ -270,7 +271,7 @@ change_file_owner (FTS *fts, FTSENT *ent,
/* Tell fts not to traverse into this hierarchy. */
fts_set (fts, ent, FTS_SKIP);
/* Ensure that we do not process "/" on the second visit. */
- ent = fts_read (fts);
+ ignore_ptr (fts_read (fts));
return false;
}
return true;
--
1.6.4.2.384.g5fc62
>From b53b85d802d58f7fa8415fc5b41b8edf7dd2fc7e Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 31 Aug 2009 18:39:41 +0200
Subject: [PATCH 6/6] maint: du: remove unnecessary initialization
* src/du.c (main): Don't set "skip_file" unnecessarily.
---
src/du.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/du.c b/src/du.c
index f746c27..24ed5e6 100644
--- a/src/du.c
+++ b/src/du.c
@@ -963,7 +963,6 @@ main (int argc, char **argv)
{
case AI_ERR_READ:
error (0, errno, _("%s: read error"), quote (files_from));
- skip_file = true;
continue;
case AI_ERR_MEM:
--
1.6.4.2.384.g5fc62
- avoiding 'dead store's reported by clang,
Jim Meyering <=