[Toybox] [PATCH] Remove some dead stores.

Daniel K. Levy alliedenvy at gmail.com
Sun Sep 6 22:23:29 PDT 2015


Remove some dead stores.

(Found by Clang static analysis.)

I'm not 100% sure if the changes to date and grep are valid;
those could use closer scrutiny.
The dead store for the "rest" variable in find looks fishy
and suggests an off-by-one error vs. the live store,
but I don't know which one is correct.
---
 toys/other/ifconfig.c | 2 +-
 toys/other/realpath.c | 2 +-
 toys/other/taskset.c  | 2 +-
 toys/posix/date.c     | 7 +++----
 toys/posix/find.c     | 4 ++--
 toys/posix/grep.c     | 6 +-----
 toys/posix/sed.c      | 4 ++--
 toys/posix/uuencode.c | 1 -
 8 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/toys/other/ifconfig.c b/toys/other/ifconfig.c
index 948043e..c071312 100644
--- a/toys/other/ifconfig.c
+++ b/toys/other/ifconfig.c
@@ -115,7 +115,7 @@ static void display_ifconfig(char *name, int
always, unsigned long long val[])
   if (!always && !(flags & IFF_UP)) return;
 
   // query hardware type and hardware address
-  i = ioctl(TT.sockfd, SIOCGIFHWADDR, &ifre);
+  ioctl(TT.sockfd, SIOCGIFHWADDR, &ifre);
 
   for (i=0; i < (sizeof(types)/sizeof(*types))-1; i++)
     if (ifre.ifr_hwaddr.sa_family == types[i].type) break;
diff --git a/toys/other/realpath.c b/toys/other/realpath.c
index ec98108..8c0f8de 100644
--- a/toys/other/realpath.c
+++ b/toys/other/realpath.c
@@ -17,7 +17,7 @@ config REALPATH
 
 void realpath_main(void)
 {
-  char **s = toys.optargs;
+  char **s;
 
   for (s = toys.optargs; *s; s++) {
     if (!realpath(*s, toybuf)) perror_msg("%s", *s);
diff --git a/toys/other/taskset.c b/toys/other/taskset.c
index 4ade5f1..dae3c04 100644
--- a/toys/other/taskset.c
+++ b/toys/other/taskset.c
@@ -50,7 +50,7 @@ GLOBALS(
 static void do_taskset(pid_t pid, int quiet)
 {
   unsigned long *mask = (unsigned long *)toybuf;
-  char *s = *toys.optargs, *failed = "failed to %s %d's affinity";
+  char *s, *failed = "failed to %s %d's affinity";
   int i, j, k;
 
   for (i=0; ; i++) {
diff --git a/toys/posix/date.c b/toys/posix/date.c
index a42de50..a2ea72a 100644
--- a/toys/posix/date.c
+++ b/toys/posix/date.c
@@ -188,15 +188,14 @@ void date_main(void)
     ((toys.optflags & FLAG_u) ? gmtime_r : localtime_r)(&now, &tm);
   }
 
-  // Fall through if no arguments
-  if (!setdate);
   // Display the date?
-  else if (*setdate == '+') {
+  if (setdate && *setdate == '+') {
     format_string = toys.optargs[0]+1;
     setdate = toys.optargs[1];
+  }
 
   // Set the date
-  } else if (setdate) {
+  if (setdate) {
     struct timeval tv;
 
     if (parse_default(setdate, &tm)) error_exit("bad date '%s'",
setdate);
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 99cf5e2..6bdb7c3 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -97,8 +97,8 @@ static int flush_exec(struct dirtree *new, struct
exec_range *aa)
     memcpy(newargs, aa->argstart, sizeof(char *)*aa->arglen);
     newargs[aa->arglen] = 0;
   } else {
-    struct double_list *dl2 = *dl;
-    int pos = aa->curly, rest = aa->arglen - aa->curly;
+    struct double_list *dl2;
+    int pos = aa->curly, rest;
 
     // Collate argument list
     memcpy(newargs, aa->argstart, sizeof(char *)*pos);
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index ffc920c..acbae85 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -97,11 +97,7 @@ static void do_grep(int fd, char *name)
         char *s = 0;
 
         for (seek = TT.e; seek; seek = seek->next) {
-          if (toys.optflags & FLAG_x) {
-            int i = (toys.optflags & FLAG_i);
-
-            if ((i ? strcasecmp : strcmp)(seek->arg, line)) s = line;
-          } else if (!*seek->arg) {
+          if (!(toys.optflags & FLAG_x) && !*seek->arg) {
             seek = &fseek;
             fseek.arg = s = line;
             break;
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index 2097532..9b0ff2c 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -704,7 +704,7 @@ static char *unescape_delimited_string(char **pstr,
char *delim, int regex)
 {
   char *to, *from, mode = 0, d;
 
-  to = from = *pstr;
+  from = *pstr;
   if (!delim || !*delim) {
     if (!(d = *(from++))) return 0;
     if (d == '\\') d = *(from++);
@@ -799,7 +799,7 @@ static void jewel_of_judgement(char **pline, long
len)
         corwin->lmatch[i] = -1;
         line++;
       } else if (*line == '/' || *line == '\\') {
-        char *s = line;
+        char *s;
 
         if (!(s = unescape_delimited_string(&line, 0, 1))) goto brand;
         if (!*s) corwin->rmatch[i] = 0;
diff --git a/toys/posix/uuencode.c b/toys/posix/uuencode.c
index 34ca701..8f499cf 100644
--- a/toys/posix/uuencode.c
+++ b/toys/posix/uuencode.c
@@ -37,7 +37,6 @@ void uuencode_main(void)
     if (!(i = xread(fd, buf, m ? sizeof(buf) : 45))) break;
 
     if (!m) xputc(i+32);
-    in = buf;
 
     for (in = buf; in-buf < i; ) {
       int j, x, bytes = i - (in-buf);
-- 

 1441603409.0


More information about the Toybox mailing list