From 96283ed4537adf80501fd3123c52d2b14b108619 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 13 May 2007 18:07:22 +0000 Subject: [PATCH] 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. --- lex.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/lex.c b/lex.c index 7403e30..cedbdb3 100644 --- a/lex.c +++ b/lex.c @@ -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 */