Various small code cleanups resulting from a code reviewing

and linting procedure:

1. Remove useless sub-expression:

   - if (*start || (!ifsspc && start > string && (nulonly || 1))) {
   + if (*start || (!ifsspc && start > string)) {

   The sub-expression "(nulonly || 1)" always evaluates to true and
   according to CVS logs seems to be just a left-over from some
   debugging and introduced by accident. Removing the sub-expression
   doesn't change semantics and a code inspection showed that the
   variable "nulonly" is also not necessary here in any way (and the
   expression would require fixing instead of removing).

2. Remove dead code:

   -                if (backslash && c == '\\') {
   -                        if (read(STDIN_FILENO, &c, 1) != 1) {
   -                                status = 1;
   -                                break;
   -                        }
   -                        STPUTC(c, p);
   -                } else if (ap[1] != NULL && strchr(ifs, c) != NULL) {
   +                if (ap[1] != NULL && strchr(ifs, c) != NULL) {

   Inspection of the control and data flow showed that variable
   "backslash" is always false (0) when the "if"-expression is
   evaluated, hence the whole block is effectively dead code.
   Additionally, the skipping of characters after a backslash is already
   performed correctly a few lines above, so this code is also not
   needed at all. According to the CVS logs and the ASH 0.2 sources,
   this code existed in this way already since its early days.

3. Cleanup Style:

   - ! trap[signo][0] == '\0' &&
   + ! (trap[signo][0] == '\0') &&

   The expression wants to ensure the trap is not assigned the empty
   string. But the "!" operator has higher precedence than "==", so the
   comparison should be put into parenthesis to form the intended way of
   expression. Nevertheless the code was effectively not really broken
   as both particular NUL comparisons are semantically equal, of course.
   But the parenthesized version is a lot more intuitive.

4. Remove shadowing variable declaration:

   - char *q;

   The declaration of symbol "q" hides another identical declaration of
   "q" in the same context. As the other "q" is already reused multiple
   times and also can be reused again without negative side-effects,
   just remove the shadowing declaration.

5. Just small cosmetics:

   - if (ifsset() != 0)
   + if (ifsset())

   The ifsset() macro is already coded by returning the boolean result
   of a comparison operator, so no need to compare this boolean result
   again against a numerical value. This also aligns the macros usage to
   the remaining existing code.

Reviewed by: stefanf@
This commit is contained in:
Ralf S. Engelschall 2005-09-06 19:30:00 +00:00
parent ff69e5b71e
commit f7d95a075c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149825
3 changed files with 4 additions and 12 deletions

View File

@ -893,7 +893,7 @@ varvalue(char *name, int quoted, int allow_split)
}
/* FALLTHROUGH */
case '*':
if (ifsset() != 0)
if (ifsset())
sep = ifsval()[0];
else
sep = ' ';
@ -1022,8 +1022,7 @@ ifsbreakup(char *string, struct arglist *arglist)
p++;
}
} while ((ifsp = ifsp->next) != NULL);
if (*start || (!ifsspc && start > string &&
(nulonly || 1))) {
if (*start || (!ifsspc && start > string)) {
sp = (struct strlist *)stalloc(sizeof *sp);
sp->text = start;
*arglist->lastp = sp;
@ -1211,7 +1210,6 @@ expmeta(char *enddir, char *name)
scopy(dp->d_name, enddir);
addfname(expdir);
} else {
char *q;
for (p = enddir, q = dp->d_name;
(*p++ = *q++) != '\0';)
continue;

View File

@ -192,13 +192,7 @@ readcmd(int argc __unused, char **argv __unused)
continue;
}
startword = 0;
if (backslash && c == '\\') {
if (read(STDIN_FILENO, &c, 1) != 1) {
status = 1;
break;
}
STPUTC(c, p);
} else if (ap[1] != NULL && strchr(ifs, c) != NULL) {
if (ap[1] != NULL && strchr(ifs, c) != NULL) {
STACKSTRNUL(p);
setvar(*ap, stackblock(), 0);
ap++;

View File

@ -382,7 +382,7 @@ onsig(int signo)
*/
if (Tflag &&
trap[signo] != NULL &&
! trap[signo][0] == '\0' &&
! (trap[signo][0] == '\0') &&
! (trap[signo][0] == ':' && trap[signo][1] == '\0'))
breakwaitcmd = 1;