Skip to content

Commit

Permalink
Uninitialized scalar variable with CID 147694-93-92
Browse files Browse the repository at this point in the history
issues:
fix coverity defects
coverity scan CID:147694, Type:Uninitialized scalar variable
coverity scan CID:147693, Type:Uninitialized scalar variable
coverity scan CID:147692, Type:Uninitialized scalar variable

Signed-off-by: cao.xuewen <[email protected]>
  • Loading branch information
heary-cao committed Oct 11, 2016
1 parent 690fe64 commit 05432de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tests/zfs-tests/cmd/largest_file/largest_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ main(int argc, char **argv)
offset_t llseek_ret = 0;
int write_ret = 0;
int err = 0;
char mybuf[5];
char mybuf[5] = "aaaa\0";
char *testfile;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;

Expand All @@ -79,8 +79,8 @@ main(int argc, char **argv)
fd = open(testfile, O_CREAT | O_RDWR, mode);
if (fd < 0) {
perror("Failed to create testfile");
err = errno;
goto out;
free(testfile);
return errno;
}

llseek_ret = lseek64(fd, offset, SEEK_SET);
Expand Down Expand Up @@ -122,6 +122,7 @@ main(int argc, char **argv)
out:
(void) unlink(testfile);
free(testfile);
close(fd);
return (err);
}

Expand Down
9 changes: 8 additions & 1 deletion tests/zfs-tests/cmd/mmapwrite/mmapwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <pthread.h>

Expand Down Expand Up @@ -67,9 +68,11 @@ int
main(int argc, char **argv)
{
int fd;
char buf[BUFSIZ];
char buf[1024];
pthread_t tid;

memset(buf, 'a', sizeof (buf));

if (argc != 2) {
(void) printf("usage: %s <file name>\n", argv[0]);
exit(1);
Expand All @@ -83,15 +86,19 @@ main(int argc, char **argv)
(void) pthread_setconcurrency(2);
if (pthread_create(&tid, NULL, mapper, &fd) != 0) {
perror("pthread_create");
close(fd);
exit(1);
}
for (;;) {
if (write(fd, buf, sizeof (buf)) == -1) {
perror("write");
close(fd);
exit(1);
}
}

close(fd);

/* NOTREACHED */
return (0);
}
9 changes: 7 additions & 2 deletions tests/zfs-tests/cmd/randfree_file/randfree_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <linux/falloc.h>

/*
Expand Down Expand Up @@ -88,11 +89,13 @@ main(int argc, char *argv[])
return (1);
}

buf = (char *)malloc(filesize);
buf = (char *)calloc(1, filesize);
memset(buf, 'c', filesize);

if (write(fd, buf, filesize) < filesize) {
free(buf);
perror("write");
close(fd);
return (1);
}

Expand All @@ -102,14 +105,16 @@ main(int argc, char *argv[])
if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
start_off, off_len) < 0) {
perror("fallocate");
close(fd);
return (1);
}
#else /* !(defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE)) */
{
perror("FALLOC_FL_PUNCH_HOLE unsupported");
close(fd);
return (1);
}
#endif /* defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) */

close(fd);
return (0);
}

0 comments on commit 05432de

Please sign in to comment.