nilassign

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 5 Imported by: 0

README

nilassign

test_and_lint

nilassign finds that assigning to invalid memory address or nil pointer dereference.

Instruction

go install github.com/sivchari/nilassign/cmd/nilassign

Usage

package main

func main() {
	{
		var i *int
		*i = 2 // ng
	}

	{
		n := &Node{}
		n.Val = 1 // ok

		*n.Pval = 1                 // ng
		n.Node.Val = 1              // ng
		n.Node.Node.Val = 1         // ng
		n.ChildNode = &Node{Val: 1} // ok
		n.PVal = &num               // ok

	}
}

type Node struct {
	Val  int
	Pval *int
	Node *Node
}
fish
go vet -vettool=(which nilassign) ./...

./main.go:6:3: this assignment occurs invalid memory address or nil pointer dereference
./main.go:13:3: this assignment occurs invalid memory address or nil pointer dereference
./main.go:14:3: this assignment occurs invalid memory address or nil pointer dereference
./main.go:15:3: this assignment occurs invalid memory address or nil pointer dereference
bash
$ go vet -vettool=`which nilassign` ./...

./main.go:6:3: this assignment occurs invalid memory address or nil pointer dereference
./main.go:13:3: this assignment occurs invalid memory address or nil pointer dereference
./main.go:14:3: this assignment occurs invalid memory address or nil pointer dereference
./main.go:15:3: this assignment occurs invalid memory address or nil pointer dereference

CI

CircleCI
- run:
    name: Install nilassign
    command: go get github.com/sivchari/nilassign

- run:
    name: Run nilassign
    command: go vet -vettool=`which nilassign` ./...
GitHub Actions
- name: Install nilassign
  run: go get github.com/sivchari/nilassign

- name: Run nilassign
  run: go vet -vettool=`which nilassign` ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "nilassign",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Analyzer is the nilassign analyzer.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL