# HG changeset patch # User Ashwini Sharma # Date 1411058862 18000 # Node ID c0c91437138bea5563235c9f26bf0e30402e72fe # Parent f0c4b7476118c9e5fc17e6cbd58c4e732b43c181 A few fixes for issues reported in static analysis. diff -r f0c4b7476118 -r c0c91437138b toys/pending/bootchartd.c --- a/toys/pending/bootchartd.c Wed Sep 17 20:21:44 2014 -0500 +++ b/toys/pending/bootchartd.c Thu Sep 18 11:47:42 2014 -0500 @@ -82,7 +82,10 @@ char *ptr; ssize_t len; - if ((len = readall(fd, toybuf, sizeof(toybuf)-1)) < 0) continue; + if ((len = readall(fd, toybuf, sizeof(toybuf)-1)) < 0) { + xclose(fd); + continue; + } toybuf[len] = '\0'; close(fd); fputs(toybuf, fp); @@ -226,10 +229,11 @@ if ((kcmd_line_fd = open("/proc/cmdline", O_RDONLY)) != -1) { ssize_t len; - len = readall(kcmd_line_fd, toybuf, sizeof(toybuf)-1); - toybuf[len] = 0; - while (--len >= 0 && !toybuf[len]) continue; - for (; len > 0; len--) if (toybuf[len] < ' ') toybuf[len] = ' '; + if ((len = readall(kcmd_line_fd, toybuf, sizeof(toybuf)-1)) > 0) { + toybuf[len] = 0; + while (--len >= 0 && !toybuf[len]) continue; + for (; len > 0; len--) if (toybuf[len] < ' ') toybuf[len] = ' '; + } else *toybuf = 0; } fprintf(hdr_fp, "system.kernel.options = %s", toybuf); close(kcmd_line_fd); diff -r f0c4b7476118 -r c0c91437138b toys/pending/fsck.c --- a/toys/pending/fsck.c Wed Sep 17 20:21:44 2014 -0500 +++ b/toys/pending/fsck.c Thu Sep 18 11:47:42 2014 -0500 @@ -37,7 +37,7 @@ char *t_list; struct double_list *devices; - int *arr_flag; + char *arr_flag; char **arr_type; int negate; int sum_status; @@ -123,18 +123,20 @@ n++; } - TT.arr_flag = xzalloc((n + 1) * sizeof(char)); + TT.arr_flag = xzalloc(n + 1); TT.arr_type = xzalloc((n + 1) * sizeof(char *)); s = TT.t_list; n = 0; while ((p = strsep(&s, ","))) { no = is_no_prefix(&p); - if (!strcmp(p, "loop")) TT.arr_flag[n] = no ? FLAG_WITH_NO_PRFX :FLAG_WITHOUT_NO_PRFX; - else if (!strncmp(p, "opts=", 5)) { + if (!strcmp(p, "loop")) { + TT.arr_flag[n] = no ? FLAG_WITH_NO_PRFX :FLAG_WITHOUT_NO_PRFX; + TT.negate = no; + } else if (!strncmp(p, "opts=", 5)) { p+=5; TT.arr_flag[n] = is_no_prefix(&p) ?FLAG_WITH_NO_PRFX :FLAG_WITHOUT_NO_PRFX; - } - else { + TT.negate = no; + } else { if (!n) TT.negate = no; if (n && TT.negate != no) error_exit("either all or none of the filesystem" " types passed to -t must be prefixed with 'no' or '!'"); @@ -221,9 +223,9 @@ return; } else { if ((pid = fork()) < 0) { + perror_msg(args[0]); for (j=0;j