[Toybox] changeset 1571:e85e5f3b87c2

enh enh at google.com
Sat Nov 22 22:55:07 PST 2014


(not sure how you guys do code review, so for now just mailing the list...)

neither clang 3.5 nor GCC 4.8 like changeset 1571:e85e5f3b87c2:

external/toybox/toys/other/lspci.c: In function 'do_lspci':
external/toybox/toys/other/lspci.c:56:61: warning: suggest braces
around empty body in an 'if' statement [-Wempty-body]
     if (readlinkat(dirfd, "driver", driver, sizeof(driver)));
                                                             ^
i think they assume you use a style like this, which also makes clang
happy (though clang would have settled for the ; on another line too):

diff --git a/toys/other/lspci.c b/toys/other/lspci.c
index 6a265a1..bf8a2e4 100644
--- a/toys/other/lspci.c
+++ b/toys/other/lspci.c
@@ -50,10 +50,11 @@ int do_lspci(struct dirtree *new)
   if (-1 == (dirfd = openat(dirtree_parentfd(new), new->name, O_RDONLY)))
     return 0;

-  // it's ok for the driver link not to be there, whatever fortify says
   *driver = 0;
   if (toys.optflags & FLAG_k)
-    if (readlinkat(dirfd, "driver", driver, sizeof(driver)));
+    if (readlinkat(dirfd, "driver", driver, sizeof(driver))) {
+      // it's ok for the driver link not to be there, whatever fortify says
+    }

   for (fields = (char*[]){"class", "vendor", "device", 0}; *fields; fields++) {
     int fd, size = 6 + 2*((toys.optflags & FLAG_e) && p == toybuf);

though this diff (which also makes both happy) feels more like your style:

diff --git a/toys/other/lspci.c b/toys/other/lspci.c
index 6a265a1..928e2d3 100644
--- a/toys/other/lspci.c
+++ b/toys/other/lspci.c
@@ -53,7 +53,7 @@ int do_lspci(struct dirtree *new)
   // it's ok for the driver link not to be there, whatever fortify says
   *driver = 0;
   if (toys.optflags & FLAG_k)
-    if (readlinkat(dirfd, "driver", driver, sizeof(driver)));
+    (void) readlinkat(dirfd, "driver", driver, sizeof(driver));

   for (fields = (char*[]){"class", "vendor", "device", 0}; *fields; fields++) {
     int fd, size = 6 + 2*((toys.optflags & FLAG_e) && p == toybuf);

 1416725707.0


More information about the Toybox mailing list