Skip to content

Commit 844fab4

Browse files
committed
Fix fuzzer.
1 parent 5ed4a6c commit 844fab4

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

driver/savepoint_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/ncruces/go-sqlite3/driver"
88
_ "github.com/ncruces/go-sqlite3/embed"
9+
_ "github.com/ncruces/go-sqlite3/internal/testcfg"
910
_ "github.com/ncruces/go-sqlite3/vfs/memdb"
1011
)
1112

driver/whitespace.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package driver
33
func notWhitespace(sql string) bool {
44
const (
55
code = iota
6-
minus
76
slash
7+
minus
88
ccomment
9-
endcomment
109
sqlcomment
10+
endcomment
1111
)
1212

1313
state := code
@@ -19,29 +19,33 @@ func notWhitespace(sql string) bool {
1919
switch state {
2020
case code:
2121
switch b {
22-
case '-':
23-
state = minus
2422
case '/':
2523
state = slash
24+
case '-':
25+
state = minus
2626
case ' ', ';', '\t', '\n', '\v', '\f', '\r':
2727
continue
2828
default:
2929
return true
3030
}
31-
case minus:
32-
if b != '-' {
33-
return true
34-
}
35-
state = sqlcomment
3631
case slash:
3732
if b != '*' {
3833
return true
3934
}
4035
state = ccomment
36+
case minus:
37+
if b != '-' {
38+
return true
39+
}
40+
state = sqlcomment
4141
case ccomment:
4242
if b == '*' {
4343
state = endcomment
4444
}
45+
case sqlcomment:
46+
if b == '\n' {
47+
state = code
48+
}
4549
case endcomment:
4650
switch b {
4751
case '/':
@@ -51,17 +55,7 @@ func notWhitespace(sql string) bool {
5155
default:
5256
state = ccomment
5357
}
54-
case sqlcomment:
55-
if b == '\n' {
56-
state = code
57-
}
5858
}
5959
}
60-
61-
switch state {
62-
case code, ccomment, endcomment, sqlcomment:
63-
return false
64-
default:
65-
return true
66-
}
60+
return state == slash || state == minus
6761
}

driver/whitespace_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package driver
33
import (
44
"context"
55
"testing"
6+
7+
_ "github.com/ncruces/go-sqlite3/embed"
8+
_ "github.com/ncruces/go-sqlite3/internal/testcfg"
69
)
710

8-
func Fuzz_isWhitespace(f *testing.F) {
11+
func Fuzz_notWhitespace(f *testing.F) {
912
f.Add("")
1013
f.Add(" ")
1114
f.Add(";")
@@ -27,10 +30,15 @@ func Fuzz_isWhitespace(f *testing.F) {
2730
defer db.Close()
2831

2932
f.Fuzz(func(t *testing.T, str string) {
33+
if len(str) > 128 {
34+
t.SkipNow()
35+
}
36+
3037
c, err := db.Conn(context.Background())
3138
if err != nil {
3239
t.Fatal(err)
3340
}
41+
defer c.Close()
3442

3543
c.Raw(func(driverConn any) error {
3644
conn := driverConn.(*conn).Conn

0 commit comments

Comments
 (0)