structinit

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package structinit implements the struct initialization syntactic analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormattedReport

func FormattedReport(res AnalysisResult) (string, bool)

FormattedReport writes res to a string and returns true if the analysis should fail.

Types

type AnalysisReqs

type AnalysisReqs struct {
	// Tag is the tag of the problem to analyze
	Tag string
}

AnalysisReqs groups the options of the analysis together

type AnalysisResult

type AnalysisResult struct {
	// InitInfos is a mapping from the named struct type to its initialization
	// information.
	InitInfos map[*types.Named]InitInfo
}

AnalysisResult is the result of the struct-init analysis.

func Analyze

func Analyze(state *ptr.State, reqs AnalysisReqs) (AnalysisResult, error)

Analyze runs the analysis on prog.

type BadReinit

type BadReinit struct {
	// Call is the function call instruction.
	Call ssa.Instruction
	// Pos is the position of the instruction.
	Pos token.Position
}

BadReinit is a function call resulting in a struct that should have specific fields reinitialized, but it hasn't.

type IncompleteInit

type IncompleteInit struct {
	// Alloc is the allocation instruction.
	Alloc ssa.Instruction
	// Struct is the struct that was allocated.
	Struct *types.Named
	// InvalidZeroedFields are the names of the fields of the struct that should be initialized
	// according to the spec, but are not.
	// Go implicitly initializes them to the zero value of the type, hence the name "zeroed" fields.
	InvalidZeroedFields []string
	// Pos is the position of the instruction.
	Pos token.Position
}

IncompleteInit is an incomplete initialization of a struct with some fields that should be initialized according to the spec but are not.

If the spec does not specify any fields, the allocation will be considered "complete", even if no fields are actually initialized in the code. We only track fields that are initialized in the same basic block as the allocation.

func (IncompleteInit) String

func (ia IncompleteInit) String() string

type IncompleteInitReport

type IncompleteInitReport struct {
	Struct              string
	InvalidZeroedFields []string
	Position            string
}

IncompleteInitReport contains the information we serialize about an incomplete initialization.

This gets written to a report file (usually json).

func (IncompleteInitReport) String

func (ir IncompleteInitReport) String() string

type InitInfo

type InitInfo struct {
	// Tag is the tag of the problem this initinfo corresponds to
	Tag string
	// IncompleteInits is a list of the incomplete initializations of the struct.
	IncompleteInits []IncompleteInit
	// InvalidWrites is a mapping of the struct field to all the invalid writes
	// to that field.
	InvalidWrites map[*types.Var][]InvalidWrite
	// BadReinits is a list of bad reinitializations
	BadReinits []BadReinit
}

InitInfo is the initialization information for a struct.

type InvalidWrite

type InvalidWrite struct {
	// Got is the value actually written.
	Got ssa.Value
	// Want is the configured value that should have been written.
	Want ssa.Value
	// Instr is the instruction performing the write.
	Instr ssa.Instruction
	// Pos is the position of the instruction.
	Pos token.Position
}

InvalidWrite is a write to a field of the struct of value Got that is not the configured value (Want).

type InvalidWriteReport

type InvalidWriteReport struct {
	StructField string
	GotValue    string
	WantValue   string
	Position    string
}

InvalidWriteReport contains the information we serialize about an invalid write.

This gets written to a report file (usually json).

func (InvalidWriteReport) String

func (ir InvalidWriteReport) String() string

Jump to

Keyboard shortcuts

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