Skip to contentSkip to conversation

gfs2_jadd: Fix static analysis warnings

PATCH New Andrew Price 1 participant 1 message Jun 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs2_jadd: Fix static analysis warnings

Fix these warnings:

gfs2/mkfs/main_jadd.c:264:8: warning: Although the value stored to 'error' is used in the enclosing expression, the value is never actually read from 'error'
gfs2/mkfs/main_jadd.c:514:15: warning: Assigned value is garbage or undefined

---
 gfs2/mkfs/main_jadd.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
gfs2/mkfs/main_jadd.c +5 -4
index ea89c96b..03134a61 100644
@@ -241,7 +241,7 @@ static void print_results(struct jadd_opts *opts)
 static int create_new_inode(struct jadd_opts *opts, uint64_t *addr)
 {
 	char *name = opts->new_inode;
-	int fd, error = 0;
+	int fd;
 
 	for (;;) {
 		fd = open(name, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0600);
@@ -261,9 +261,10 @@ static int create_new_inode(struct jadd_opts *opts, uint64_t *addr)
 	if (addr != NULL) {
 		struct stat st;
 
-		if ((error = fstat(fd, &st))) {
+		if (fstat(fd, &st) == -1) {
 			perror("fstat");
-			return close(fd);
+			close(fd);
+			return -1;
 		}
 		*addr = st.st_ino;
 	}
@@ -481,7 +482,7 @@ static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
 	unsigned int x, blocks =
 		sdp->jsize << (20 - sdp->sd_sb.sb_bsize_shift);
 	struct gfs2_log_header lh;
-	uint64_t seq = RANDOM(blocks), addr;
+	uint64_t seq = RANDOM(blocks), addr = 0;
 	off_t off = 0;
 
 	if ((fd = create_new_inode(opts, &addr)) < 0)
Signature · 1 line
2.26.2