mirror of
https://github.com/github/codeql.git
synced 2026-01-29 22:32:58 +01:00
Add test with multiple switch statements
This commit is contained in:
@@ -86,6 +86,25 @@ func switchStatementReturningNilOnlyWhenConstant(s string) *string {
|
||||
return &str
|
||||
}
|
||||
|
||||
func multipleSwitchStatementReturningTrueOnlyWhenConstant(s string, t string) bool {
|
||||
switch s {
|
||||
case constantGlobalVariable, "string literal":
|
||||
return true
|
||||
case getRandomString():
|
||||
return false
|
||||
}
|
||||
switch s {
|
||||
case "another string literal":
|
||||
return true
|
||||
}
|
||||
switch t {
|
||||
case "another string literal":
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func switchStatementWithoutUsefulInfo(s string) bool {
|
||||
switch s {
|
||||
case constantGlobalVariable, "string literal":
|
||||
@@ -149,6 +168,15 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
s := source()
|
||||
if multipleSwitchStatementReturningTrueOnlyWhenConstant(s, getRandomString()) {
|
||||
sink(s)
|
||||
} else {
|
||||
sink(s) // $dataflow=s
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
s := source()
|
||||
if switchStatementWithoutUsefulInfo(s) {
|
||||
|
||||
Reference in New Issue
Block a user