comparison toys/other/lspci.c @ 1572:da1bf31ed322 draft

Tweak the "ignoring return value" fortify workaround for readlinkat. We zero the buffer and if the link read fails that's left alone, so it's ok for the symlink not to be there. Unfortunately, typecasting the return value to (void) doesn't shut up gcc, and having an if(); with the semicolon on the same line doesn't shut up llvm. (The semicolon on a new line would, but C does not have significant whitespace and I'm not going to humor llvm if it plans to start.) So far, empty curly brackets consistently get the warning to shut up.
author Rob Landley <rob@landley.net>
date Mon, 24 Nov 2014 17:23:23 -0600
parents e85e5f3b87c2
children
comparison
equal deleted inserted replaced
1571:e85e5f3b87c2 1572:da1bf31ed322
51 return 0; 51 return 0;
52 52
53 // it's ok for the driver link not to be there, whatever fortify says 53 // it's ok for the driver link not to be there, whatever fortify says
54 *driver = 0; 54 *driver = 0;
55 if (toys.optflags & FLAG_k) 55 if (toys.optflags & FLAG_k)
56 if (readlinkat(dirfd, "driver", driver, sizeof(driver))); 56 if (readlinkat(dirfd, "driver", driver, sizeof(driver))) {};
57 57
58 for (fields = (char*[]){"class", "vendor", "device", 0}; *fields; fields++) { 58 for (fields = (char*[]){"class", "vendor", "device", 0}; *fields; fields++) {
59 int fd, size = 6 + 2*((toys.optflags & FLAG_e) && p == toybuf); 59 int fd, size = 6 + 2*((toys.optflags & FLAG_e) && p == toybuf);
60 *p = 0; 60 *p = 0;
61 61