Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False Positive when error is not returned from function #295

Open
QianKuang8 opened this issue Dec 2, 2024 · 0 comments
Open

False Positive when error is not returned from function #295

QianKuang8 opened this issue Dec 2, 2024 · 0 comments

Comments

@QianKuang8
Copy link

Case 1 use switch and case 2 use if. Both of them are failed.

package main

import "fmt"

// not OK
func case1() {
	var s *string
	var err error
	situation := 1
	switch situation {
	case 1:
		tmp := "one"
		s = &tmp
	default:
		err = fmt.Errorf("error")
	}
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(*s)
}

// not OK
func case2() {
	var s *string
	var err error
	situation := 1
	if situation == 1 {
		tmp := "one"
		s = &tmp
	} else {
		err = fmt.Errorf("error")
	}
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(*s)
}

func main() {
	case1()
	case2()
}

I check the issues and this is similar to #110 but more simple with a bit different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant