Skip to content

False positive with distributed nil-checking guards #378

@sonalmahajan15

Description

@sonalmahajan15

The dereference of x below is completely safe. NilAway reports a false positive since it is likely evaluating each nil check independently instead of collectively.

func foo(x, y *int) int {
	if x == nil && y == nil {
		return 0
	}
	if x != nil && y == nil {
		return 1
	}
	if x == nil && y != nil {
		return 2
	}
	return *x
}

func test() {
	n := 10

	foo(nil, nil)
	foo(&n, nil)
	foo(nil, &n)
	foo(&n, &n)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    false positiveRequires more analysis and support

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions