Skip to content

Commit 38c1feb

Browse files
authored
Merge pull request #204 from edznux-dd/nil-pointer-deref
[bugfix] Nil pointer deref
2 parents 9cff4c5 + a458e63 commit 38c1feb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

select_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,8 @@ func ExampleSelectBuilder_LateralAs() {
417417
// Output:
418418
// SELECT salesperson.name, max_sale.amount, max_sale.customer_name FROM salesperson, LATERAL (SELECT amount, customer_name FROM all_sales WHERE all_sales.salesperson_id = salesperson.id ORDER BY amount DESC LIMIT ?) AS max_sale
419419
}
420+
421+
func TestNilPointerWhere(t *testing.T) {
422+
NewSelectBuilder().SQL("$0").Build()
423+
NewSelectBuilder().SQL("$0").BuildWithFlavor(DefaultFlavor)
424+
}

whereclause.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var _ Builder = new(whereClauseProxy)
6060

6161
// BuildWithFlavor builds a WHERE clause with the specified flavor and initial arguments.
6262
func (wc *WhereClause) BuildWithFlavor(flavor Flavor, initialArg ...interface{}) (sql string, args []interface{}) {
63-
if len(wc.clauses) == 0 {
63+
if wc == nil || len(wc.clauses) == 0 {
6464
return "", nil
6565
}
6666

@@ -128,6 +128,9 @@ func (wc *WhereClause) AddWhereExpr(args *Args, andExpr ...string) *WhereClause
128128

129129
// AddWhereClause adds all clauses in the whereClause to the wc.
130130
func (wc *WhereClause) AddWhereClause(whereClause *WhereClause) *WhereClause {
131+
if wc == nil {
132+
return nil
133+
}
131134
if whereClause == nil {
132135
return wc
133136
}

0 commit comments

Comments
 (0)