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

Critical bug-risk: Poorly formed nilness guards #779

Open
philipjonsen opened this issue Sep 22, 2023 · 0 comments
Open

Critical bug-risk: Poorly formed nilness guards #779

philipjonsen opened this issue Sep 22, 2023 · 0 comments

Comments

@philipjonsen
Copy link

DESCRIPTION
Poorly formed nilness guards can be fatal as they might lead to unwanted panic because of nil pointer dereferences. Depending on the binary expression, the logic might not work as expected because of the poorly formed guards. In a binary expression, it is crucial to creating good nilness guards so that executing the other operand in the expression is safe.

BAD PRACTICE:
if cmd == nil && cmd.Execute() == 0 {
// do something
}

if cmd != nil || cmd.Execute() == 0 {
// do something
}

RECOMMENDED:
if cmd != nil && cmd.Execute() == 0 {
// do something
}

if cmd == nil || cmd.Execute() == 0 {
// do something
}

Problematic code to fix: /shentu/blob/master/app/export.go#L75-L75

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