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

Overview

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` ./...
You might also like...
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+

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

Tool: ptrls prints result of pointer analysis

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

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

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

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

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

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

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

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

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

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

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-

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

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

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

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

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/[email protected] Usag

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

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

Releases(v0.1.1)
Owner
sivchari
Bon sens
sivchari
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,

neglect-yp 3 Jun 9, 2022
Tool: ptrls prints result of pointer analysis

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

GoStaticAnalysis 1 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

GoStaticAnalysis 7 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/[email protected]

Anton Telyshev 13 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,

neglect-yp 3 Jun 9, 2022
Const-pointer - Const Pointer Considerations

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

null 0 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

ShiftStack 0 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

Boris Nagaev 0 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

prequist 3 Aug 26, 2021
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

Pavel Shabarkin 57 Nov 23, 2022