Message ID | 1512063084-12105-2-git-send-email-ari@tuxera.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, Nov 30, 2017 at 7:31 PM, Ari Sundholm <ari@tuxera.com> wrote: > Add a check for the return value of getcwd(). Fix another check > which mistakenly checks if the return value is less than zero > instead of checking whether the return value is NULL. > > Signed-off-by: Ari Sundholm <ari@tuxera.com> > --- > ltp/fsstress.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/ltp/fsstress.c b/ltp/fsstress.c > index 13d5dd5..028c232 100644 > --- a/ltp/fsstress.c > +++ b/ltp/fsstress.c > @@ -495,7 +495,7 @@ int main(int argc, char **argv) > > (void)mkdir(dirname, 0777); > if (logname && logname[0] != '/') { > - if (getcwd(rpath, sizeof(rpath)) < 0){ > + if (!getcwd(rpath, sizeof(rpath))){ > perror("getcwd failed"); > exit(1); > } > @@ -970,6 +970,10 @@ doproc(void) > } > top_ino = statbuf.st_ino; > homedir = getcwd(NULL, 0); > + if (!homedir) { > + perror("getcwd failed"); > + _exit(1); > + } > seed += procid; > srandom(seed); > if (namerand) The change itself looks correct, but I have no idea what's the purpose of saving homedir. It is only used in DEBUG code to chdir(homedir) before abort(). Is there any obscure meaning to that chdir() that I don't understand? Amir. -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 13d5dd5..028c232 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -495,7 +495,7 @@ int main(int argc, char **argv) (void)mkdir(dirname, 0777); if (logname && logname[0] != '/') { - if (getcwd(rpath, sizeof(rpath)) < 0){ + if (!getcwd(rpath, sizeof(rpath))){ perror("getcwd failed"); exit(1); } @@ -970,6 +970,10 @@ doproc(void) } top_ino = statbuf.st_ino; homedir = getcwd(NULL, 0); + if (!homedir) { + perror("getcwd failed"); + _exit(1); + } seed += procid; srandom(seed); if (namerand)
Add a check for the return value of getcwd(). Fix another check which mistakenly checks if the return value is less than zero instead of checking whether the return value is NULL. Signed-off-by: Ari Sundholm <ari@tuxera.com> --- ltp/fsstress.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)