There are two issues PW.PARAMETER_HIDDEN (declaration hides parameter 'devname') and INTEGER_OVERFLOW. Signed-off-by: Xiao Ni <xni@xxxxxxxxxx> --- Incremental.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Incremental.c b/Incremental.c index 83db071214ee..33e6814de9d0 100644 --- a/Incremental.c +++ b/Incremental.c @@ -770,7 +770,7 @@ static int count_active(struct supertype *st, struct mdinfo *sra, replcnt++; st->ss->free_super(st); } - if (max_journal_events >= max_events - 1) + if (max_events > 0 && max_journal_events >= max_events - 1) bestinfo->journal_clean = 1; if (!avail) @@ -1113,7 +1113,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, int fd = -1; struct mdinfo info; struct supertype *st2 = NULL; - char *devname = NULL; + char *dev_path_name = NULL; unsigned long long devsectors; char *pathlist[2]; @@ -1142,14 +1142,14 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, domain_free(domlist); domlist = NULL; - if (asprintf(&devname, "/dev/disk/by-path/%s", de->d_name) != 1) { - devname = NULL; + if (asprintf(&dev_path_name, "/dev/disk/by-path/%s", de->d_name) != 1) { + dev_path_name = NULL; goto next; } - fd = open(devname, O_RDONLY); + fd = open(dev_path_name, O_RDONLY); if (fd < 0) goto next; - if (get_dev_size(fd, devname, &devsectors) == 0) + if (get_dev_size(fd, dev_path_name, &devsectors) == 0) goto next; devsectors >>= 9; @@ -1188,8 +1188,8 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, if (chosen == NULL || chosen_size < info.component_size) { chosen_size = info.component_size; free(chosen); - chosen = devname; - devname = NULL; + chosen = dev_path_name; + dev_path_name = NULL; if (chosen_st) { chosen_st->ss->free_super(chosen_st); free(chosen_st); @@ -1199,7 +1199,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, } next: - free(devname); + free(dev_path_name); domain_free(domlist); dev_policy_free(pol2); if (st2) @@ -1246,7 +1246,7 @@ static int is_bare(int dfd) /* OK, first 4K appear blank, try the end. */ get_dev_size(dfd, NULL, &size); - if (lseek(dfd, size-4096, SEEK_SET) < 0 || + if ((size >= 4096 && lseek(dfd, size-4096, SEEK_SET) < 0) || read(dfd, buf, 4096) != 4096) return 0; -- 2.32.0 (Apple Git-132)