index f22b23f..0b991c5 100644 --- a/Src/Modules/files.c +++ b/Src/Modules/files.c @@ -428,7 +428,8 @@ recursivecmd(char *nam, int opt_noerr, int opt_recurse, int opt_safe, if ((err & 2) && ds.dirfd >= 0 && restoredir(&ds) && zchdir(pwd)) { zsfree(pwd); pwd = ztrdup("/"); - chdir(pwd); + if (chdir(pwd) < 0) + zwarn("failed to chdir(%s): %e", pwd, errno); } if (ds.dirfd >= 0) close(ds.dirfd); index d825c7f..422c707 100644 --- a/Src/Modules/mapfile.c +++ b/Src/Modules/mapfile.c @@ -92,7 +92,8 @@ setpmmapfile(Param pm, char *value) * First we need to make sure the file is long enough for * when we msync. On AIX, at least, we just get zeroes otherwise. */ - ftruncate(fd, len); + if (ftruncate(fd, len) < 0) + zwarn("ftruncate failed: %e", errno); memcpy(mmptr, value, len); #ifndef MS_SYNC #define MS_SYNC 0 @@ -102,7 +103,8 @@ setpmmapfile(Param pm, char *value) * Then we need to truncate again, since mmap() always maps complete * pages. Honestly, I tried it without, and you need both. */ - ftruncate(fd, len); + if (ftruncate(fd, len) < 0) + zwarn("ftruncate failed: %e", errno); munmap(mmptr, len); } #else /* don't USE_MMAP */ index 12a9f0d..0dc9486 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -2043,8 +2043,9 @@ zfgetinfo(char *prompt, int noecho) fflush(stderr); } - fgets(instr, 256, stdin); - if (instr[len = strlen(instr)-1] == '\n') + if (fgets(instr, 256, stdin) == NULL) + instr[len = 0] = '\0'; + else if (instr[len = strlen(instr)-1] == '\n') instr[len] = '\0'; strret = dupstring(instr); index 050101f..95aca06 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -795,16 +795,16 @@ bin_cd(char *nam, char **argv, Options ops, int func) setjobpwd(); zsfree(pwd); pwd = metafy(zgetcwd(), -1, META_DUP); - } else if (stat(".", &st2) < 0) - chdir(unmeta(pwd)); - else if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) { + } else if (stat(".", &st2) < 0) { + if (chdir(unmeta(pwd)) < 0) + zwarn("unable to chdir(%s): %e", pwd, errno); + } else if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) { if (chasinglinks) { setjobpwd(); zsfree(pwd); pwd = metafy(zgetcwd(), -1, META_DUP); - } else { - chdir(unmeta(pwd)); - } + } else if (chdir(unmeta(pwd)) < 0) + zwarn("unable to chdir(%s): %e", pwd, errno); } unqueue_signals(); return 0; index ed7c087..4f15ebe 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2722,7 +2722,8 @@ execcmd(Estate state, int input, int output, int how, int last1) #ifdef HAVE_NICE /* Check if we should run background jobs at a lower priority. */ if ((how & Z_ASYNC) && isset(BGNICE)) - nice(5); + if (nice(5) < 0) + zwarn("nice(5) failed: %e", errno); #endif /* HAVE_NICE */ } else if (is_cursh) { index 38ceac3..637976d 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -2291,9 +2291,9 @@ savehistfile(char *fn, int err, int writeflags) #ifdef HAVE_FCHMOD if (old_exists && out) { #ifdef HAVE_FCHOWN - fchown(fileno(out), sb.st_uid, sb.st_gid); + if (fchown(fileno(out), sb.st_uid, sb.st_gid) < 0) {} /* IGNORE FAILURE */ #endif - fchmod(fileno(out), sb.st_mode); + if (fchmod(fileno(out), sb.st_mode) < 0) {} /* IGNORE FAILURE */ } #endif } index 7a983d4..340ceb8 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -5422,7 +5422,8 @@ lchdir(char const *path, struct dirsav *d, int hard) } #ifdef HAVE_LSTAT if (*path == '/') - chdir("/"); + if (chdir("/") < 0) + zwarn("failed to chdir(/): %e", errno); for(;;) { while(*path == '/') path++;