diff --git a/nshlib/nsh_test.c b/nshlib/nsh_test.c index b23b3d7cd..b04dfdbf2 100644 --- a/nshlib/nsh_test.c +++ b/nshlib/nsh_test.c @@ -181,7 +181,7 @@ static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, { struct stat buf; FAR char *fullpath; - int ret; + int ret = TEST_ERROR; /* -n STRING */ @@ -206,21 +206,18 @@ static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, */ fullpath = nsh_getfullpath(vtbl, argv[1]); - if (!fullpath) + if (fullpath) { - return TEST_FALSE; + ret = stat(fullpath, &buf); + nsh_freefullpath(fullpath); } - ret = stat(fullpath, &buf); - nsh_freefullpath(fullpath); - if (ret != 0) { - /* The file does not exist (or another error occurred) -- return - * FALSE. + /* The file does not exist (or another error occurred) */ - return TEST_FALSE; + memset(&buf, 0, sizeof(struct stat)); } /* -b FILE */ @@ -256,7 +253,7 @@ static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, { /* Return true if the file exists */ - return TEST_TRUE; + return ret == 0 ? TEST_TRUE : TEST_FALSE; } /* -f FILE */ @@ -333,14 +330,20 @@ static int expression(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) goto errout_syntax; } - i += 2; value = unaryexpression(vtbl, argv); + if (value == TEST_ERROR) + { + goto do_binary; + } + + i += 2; } /* Check for binary operations on simple, typed arguments */ else { +do_binary: if (argc < 3) { goto errout_syntax;