Fix null pointer issue found by fuzz test
This commit is contained in:
parent
c03f7d6576
commit
74ea365c5a
|
@ -1,6 +1,7 @@
|
|||
package qcode
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
@ -207,6 +208,9 @@ func (l *lexer) errorf(format string, args ...interface{}) stateFn {
|
|||
|
||||
// lex creates a new scanner for the input string.
|
||||
func lex(input string) (*lexer, error) {
|
||||
if len(input) == 0 {
|
||||
return nil, errors.New("empty query")
|
||||
}
|
||||
l := &lexer{
|
||||
input: input,
|
||||
items: make([]item, 0, 100),
|
||||
|
|
|
@ -57,3 +57,11 @@ func TestCompile(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyCompile(t *testing.T) {
|
||||
qcompile, _ := NewCompiler(Config{})
|
||||
_, err := qcompile.CompileQuery(``)
|
||||
if err == nil {
|
||||
t.Fatal(errors.New("expecting an error"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,7 +336,13 @@ func (com *Compiler) compileQuery(op *Operation) (*Query, error) {
|
|||
}
|
||||
}
|
||||
|
||||
fil, ok := com.fm[selRoot.Table]
|
||||
var ok bool
|
||||
var fil *Exp
|
||||
|
||||
if selRoot != nil {
|
||||
fil, ok = com.fm[selRoot.Table]
|
||||
}
|
||||
|
||||
if !ok || fil == nil {
|
||||
fil = com.fl
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue