Don't crash the compiler when redirection sign is invalid.

This fixes #484.
This commit is contained in:
Qi Xiao 2017-09-30 21:00:53 +08:00
parent 3f73d8474b
commit 01d611aabd
2 changed files with 5 additions and 2 deletions

View File

@ -378,6 +378,10 @@ func (cp *compiler) redir(n *parse.Redir) OpFunc {
sourceIsFd := n.RightIsFd
mode := n.Mode
flag := makeFlag(mode)
if flag == -1 {
// TODO: Record and get redirection sign position
cp.errorf("bad redirection sign")
}
return func(ec *EvalCtx) {
var dst int

View File

@ -88,8 +88,7 @@ func makeFlag(m parse.RedirMode) int {
case parse.Append:
return os.O_WRONLY | os.O_CREATE | os.O_APPEND
default:
// XXX should report parser bug
panic("bad RedirMode; parser bug")
return -1
}
}