summaryrefslogtreecommitdiff
path: root/util/nvmutil/nvmutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/nvmutil/nvmutil.c')
-rw-r--r--util/nvmutil/nvmutil.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 759edea0..da954b32 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -143,7 +143,8 @@ readFromFile(int *fd, uint8_t *buf, const char *path, int flags, size_t size)
} else if (((*fd) = open(path, flags)) == -1) {
return -1;
} else if (size == SIZE_8KB) {
- fstat((*fd), &st);
+ if (fstat((*fd), &st) == -1)
+ return -1;
if ((st.st_size != SIZE_8KB) && strcmp(path, "/dev/urandom")) {
fprintf(stderr, "Bad file size\n");
errno = ECANCELED;
@@ -153,6 +154,8 @@ readFromFile(int *fd, uint8_t *buf, const char *path, int flags, size_t size)
if (errno == ENOTDIR)
errno = 0;
+ else if (errno != 0)
+ return -1;
return read((*fd), buf, size);
}
@@ -179,7 +182,7 @@ cmd_setmac(const char *strMac)
if (errno != 0)
return;
goto invalid_mac_address;
- } else if ((byte == 0 && (nib == 1))) {
+ } else if ((byte == 0) && (nib == 1)) {
val8 &= 0xE;
val8 |= 2;
}
@@ -244,12 +247,12 @@ rhex(void)
static uint8_t *rbuf = NULL;
static size_t rindex = BUFSIZ;
- if ((rindex == BUFSIZ)) {
+ if (rindex == BUFSIZ) {
rindex = 0;
- if ((rbuf == NULL))
+ if (rbuf == NULL)
if ((rbuf = (uint8_t *) malloc(BUFSIZ)) == NULL)
err(1, NULL);
- if ((rfd != -1)) {
+ if (rfd != -1) {
close(rfd);
rfd = -1;
}
@@ -258,7 +261,7 @@ rhex(void)
warn("%s", "/dev/urandom");
return 16;
}
- if ((errno != 0))
+ if (errno != 0)
return 16;
}
@@ -355,7 +358,7 @@ cmd_swap(void)
part0 = validChecksum(0);
part1 = validChecksum(1);
- if ((part0 | part1)) {
+ if (part0 || part1) {
for(part0 = 0; part0 < SIZE_4KB; part0++) {
gbe[part0] ^= gbe[part1 = (part0 | SIZE_4KB)];
gbe[part1] ^= gbe[part0];