The analyzer has detected code that contains two adjacent if statements with identical conditions. This is either a potential error or redundant code.
func Logging(s1 *string, s2 *string) {
if s1 != nil {
fmt.Println(*s1)
}
if s1 != nil {
fmt.Println(*s2)
}
}
The code contains an error in the second condition. The s1 variable is checked twice when s2 should be checked instead.
The fixed code:
func Logging(s1 *string, s2 *string) {
if s1 != nil {
fmt.Println(*s1)
}
if s2 != nil {
fmt.Println(*s2)
}
}
This warning does not always mean there is an error in the code. It may be redundant:
func Logging2(toFile bool, s1 string, s2 string) {
if toFile {
fmt.Println(s1)
}
if toFile {
fmt.Println(s2)
}
}
The code is correct but slightly inefficient because it checks the value of the same boolean variable twice. It can be rewritten as follows:
func Logging2(toFile bool, s1 string, s2 string) {
if toFile {
fmt.Println(s1)
fmt.Println(s2)
}
}
You can look at examples of errors detected by the V8017 diagnostic. |
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders: