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

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` ./...
Owner
Similar Resources

A helper function to create a pointer to a new object in Go 1.18+

A helper function to create a pointer to a new object in Go 1.18+

A helper function to create a pointer to a new object in Go 1.18+

Nov 9, 2022

Tugas Alta Immersive Backend Golang Fundamental Programming (Pointer, Struct, Method, Interface)

Tugas Alta Immersive Backend Golang Fundamental Programming (Pointer, Struct, Method, Interface)

Tatacara Melakukan Setup Tugas clone project ini dengan cara git clone https://github.com/Immersive-Backend-Resource/Pointer-Struct-Method-Interface.g

Jan 9, 2022

Tool: ptrls prints result of pointer analysis

ptrls Install $ go install github.com/gostaticanalysis/ptrls/cmd/ptrls@latest Usage $ cd testdata/a $ cat a.go package main func main() { f(map[str

Feb 1, 2022

What is more efficient value or pointer method receivers in Go?

What is more efficient value or pointer method receivers? A) Why would you think struct is more efficient? You are making single call to fetch struct

Feb 4, 2022

Prep finds all SQL statements in a Go package and instruments db connection with prepared statements

Prep Prep finds all SQL statements in a Go package and instruments db connection with prepared statements. It allows you to benefit from the prepared

Dec 10, 2022

smartcrop finds good image crops for arbitrary crop sizes

smartcrop finds good image crops for arbitrary crop sizes

smartcrop smartcrop finds good image crops for arbitrary sizes. It is a pure Go implementation, based on Jonas Wagner's smartcrop.js Image: https://ww

Jan 8, 2023

Parses Go tracebacks and finds possible deadlocks

findlock Parses Go tracebacks and finds possible deadlocks This works by checking how many locks have the same memory address. If there are multiple g

Nov 19, 2022

A cowin bot that gives you an update whenever it finds a vacancy in your region

go-cowin-bot A cowin bot that will give you an update on discord whenever it finds a vacancy for the parameters provided Setup: download go-cowin-bot

Mar 29, 2022

Finds common flaws in passwords. Like cracklib, but written in Go.

crunchy Finds common flaws in passwords. Like cracklib, but written in Go. Detects: ErrEmpty: Empty passwords ErrTooShort: Too short passwords ErrNoDi

Dec 30, 2022

Analyzer: debugcode finds debug codes

debugcode debugcode finds debug codes. builtinprint: finds calling builtin print or println. commentout: finds a commented out debug code without reas

Aug 16, 2021

noioutil finds files using the "io/ioutil" package.

noioutil noioutil finds files using the "io/ioutil" package.

Dec 28, 2021

Go binary that finds .EXEs and .DLLs on the system that don't have security controls enabled

Go Hunt Weak PEs Go binary that finds .EXEs and .DLLs on the system that don't have security controls enabled (ASLR, DEP, CFG etc). Usage $ ./go-hunt-

Oct 28, 2021

Scans backup folders on target sites. Searches archived files in the folders it finds.

netwons_backup Scans backup folders on target sites. Searches archived files in the folders it finds. 1 -- files/extensions.txt - This adds new exten

Nov 4, 2021

This service finds and — if necessary — generates icons for web sites

This service finds and — if necessary — generates icons for web sites

favicon-service (besticon) This is a favicon service: Supports favicon.ico and apple-touch-icon.png Simple URL API Fallback icon generation Docker ima

Nov 2, 2021

Finds an identifiable hash value for each version of GitLab vulnerable to CVE-2021-22205

Finds an identifiable hash value for each version of GitLab vulnerable to CVE-2021-22205

Sep 20, 2022

This is a small utility that finds unused exported Go symbols (functions, methods ...) in Go

This is a small utility that finds unused exported Go symbols (functions, methods ...) in Go. For all other similar use cases

Nov 8, 2022

A tool that finds and removes unnecessary lines from .gitignore files.

Allyignore A tool that finds and removes unnecessary lines from .gitignore files. Installation go install github.com/Allyedge/allyignore@latest Usag

May 10, 2022

Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications.

Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications.

Linear Allocator for Golang Goal Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications. Pote

Dec 20, 2022

gpu-memory-monitor is a metrics server for collecting GPU memory usage of kubernetes pods.

gpu-memory-monitor is a metrics server for collecting GPU memory usage of kubernetes pods. If you have a GPU machine, and some pods are using the GPU device, you can run the container by docker or kubernetes when your GPU device belongs to nvidia. The gpu-memory-monitor will collect the GPU memory usage of pods, you can get those metrics by API of gpu-memory-monitor

Jul 27, 2022
Retnilnil is a static analysis tool to detect `return nil, nil`

retnilnil retnilnil is a static analysis tool for Golang that detects return nil, nil in functions with (*T, error) as the return type. func f() (*T,

Jun 9, 2022
Tool: ptrls prints result of pointer analysis

ptrls Install $ go install github.com/gostaticanalysis/ptrls/cmd/ptrls@latest Usage $ cd testdata/a $ cat a.go package main func main() { f(map[str

Feb 1, 2022
Analyzer: debugcode finds debug codes

debugcode debugcode finds debug codes. builtinprint: finds calling builtin print or println. commentout: finds a commented out debug code without reas

Aug 16, 2021
The Golang linter that checks that there is no simultaneous return of `nil` error and an invalid value.

nilnil Checks that there is no simultaneous return of nil error and an invalid value. Installation & usage $ go install github.com/Antonboom/nilnil@la

Dec 14, 2022
Retnilnil is a static analysis tool to detect `return nil, nil`

retnilnil retnilnil is a static analysis tool for Golang that detects return nil, nil in functions with (*T, error) as the return type. func f() (*T,

Jun 9, 2022
Const-pointer - Const Pointer Considerations

Const Pointer Considerations What does this code obviously do? const ( MONDAY =

Jan 28, 2022
Openstack Invalid HTTPS Cert Scanner

Openstack Invalid HTTPS Cert Scanner Scans all OpenStack API endpoints in a given catalog and warns about legacy HTTPS certificates that do not list t

Jan 18, 2022
Golang: unify nil and empty slices and maps

unifynil, unify nil and empty slices and maps in Golang Empty slices and maps can be nil or not nil in Go. It may become a nightmare in tests and JSON

Jan 16, 2022
ptypes is a pointer-based box typing system for golang.

ptypes bypass go's type system through unsafe pointers the paradigm is to created a "boxed" type with .From and then use whatever types we want by ass

Aug 26, 2021
Pointer was developed for massive hunting and mapping Cobalt Strike servers exposed on the internet.
Pointer was developed for massive hunting and mapping Cobalt Strike servers exposed on the internet.

Description The Pointer was developed for hunting and mapping Cobalt Strike servers exposed to the Internet. The tool includes the complete methodolog

Nov 23, 2022