Workaround for Coverity CID#1: the Prevent parser didn't recognise there

were multiple possible values for c inside the code.

Rewrite code in question to use if instead of switch; optimise while here.
This commit is contained in:
tg 2007-05-13 18:07:22 +00:00
parent 0989f7da67
commit 96283ed453
1 changed files with 10 additions and 23 deletions

33
lex.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.30 2007/05/10 19:22:11 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.31 2007/05/13 18:07:22 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. */
@ -654,41 +654,28 @@ yylex(int cf)
if (wp == dp && state == SBASE) {
Xfree(ws, wp); /* free word */
/* no word, process LEX1 character */
switch (c) {
default:
return c;
case '|':
case '&':
case ';':
if ((c == '|') || (c == '&') || (c == ';') || (c == '('/*)*/)) {
if ((c2 = getsc()) == c)
c = (c == ';') ? BREAK :
(c == '|') ? LOGOR :
(c == '&') ? LOGAND :
/*
* this is the place where
* ((...); (...))
* and similar is broken
*/
(c == '(' /*)*/ ) ? MDPAREN :
YYERRCODE;
else if (c == '|' && c2 == '&')
c = COPROC;
else
ungetsc(c2);
return c;
case '\n':
} else if (c == '\n') {
gethere();
if (cf & CONTIN)
goto Again;
return c;
case '(': /*)*/
if ((c2 = getsc()) == '(') /*)*/
/* XXX need to handle ((...); (...)) */
c = MDPAREN;
else
ungetsc(c2);
return c;
/*(*/
case ')':
return c;
}
return (c);
}
*wp++ = EOS; /* terminate word */