-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid stack overflow in sourcetype.IsSourceType. (#322)
- Loading branch information
mlevesquedion
authored
Jul 13, 2021
1 parent
4c61727
commit 99e3a7f
Showing
3 changed files
with
107 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sourcetype | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-flow-levee/internal/pkg/config" | ||
"github.com/google/go-flow-levee/internal/pkg/fieldtags" | ||
"golang.org/x/tools/go/analysis" | ||
"golang.org/x/tools/go/analysis/analysistest" | ||
"golang.org/x/tools/go/analysis/passes/buildssa" | ||
) | ||
|
||
var Analyzer = &analysis.Analyzer{ | ||
Name: "sourcetype_test", | ||
Doc: "This analyzer is used to test the sourcetype package.", | ||
Run: run, | ||
Requires: []*analysis.Analyzer{buildssa.Analyzer}, | ||
} | ||
|
||
func run(pass *analysis.Pass) (interface{}, error) { | ||
ssaInput := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) | ||
|
||
c := &config.Config{} | ||
tf := make(fieldtags.ResultType) | ||
|
||
for _, fn := range ssaInput.SrcFuncs { | ||
for _, p := range fn.Params { | ||
_ = IsSourceType(c, tf, p.Type()) | ||
} | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func TestSourceTypeDoesNotStackOverflow(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
analysistest.Run(t, testdata, Analyzer, "./...") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package test | ||
|
||
type SelfReferential map[string]SelfReferential | ||
|
||
func selfReferential(s SelfReferential) { | ||
} | ||
|
||
type CoReferentialA CoReferentialB | ||
type CoReferentialB *CoReferentialA | ||
|
||
func coReferential(c CoReferentialA) { | ||
} | ||
|
||
type DeepSelfReferential [1][]chan DeepSelfReferential | ||
|
||
func deepSelfReferential(d DeepSelfReferential) { | ||
} |