mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-30 02:34:14 +03:00
Fix coverity defects: CID 147692, 147693, 147694
CID:147692, Type:Uninitialized scalar variable CID:147693, Type:Uninitialized scalar variable CID:147694, Type:Uninitialized scalar variable Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: cao.xuewen <cao.xuewen@zte.com.cn> Closes #5252
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <linux/falloc.h>
|
||||
|
||||
/*
|
||||
@@ -54,7 +55,7 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *filename = NULL;
|
||||
char *buf;
|
||||
char *buf = NULL;
|
||||
size_t filesize = 0;
|
||||
off_t start_off = 0;
|
||||
off_t off_len = 0;
|
||||
@@ -88,11 +89,18 @@ main(int argc, char *argv[])
|
||||
return (1);
|
||||
}
|
||||
|
||||
buf = (char *)malloc(filesize);
|
||||
buf = (char *)calloc(1, filesize);
|
||||
if (buf == NULL) {
|
||||
perror("write");
|
||||
close(fd);
|
||||
return (1);
|
||||
}
|
||||
memset(buf, 'c', filesize);
|
||||
|
||||
if (write(fd, buf, filesize) < filesize) {
|
||||
free(buf);
|
||||
perror("write");
|
||||
close(fd);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -102,14 +110,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user